pub struct SyntaxHighlighter { /* private fields */ }Implementations§
Source§impl SyntaxHighlighter
impl SyntaxHighlighter
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/editor_demo.rs (line 73)
47 fn new(cx: &mut Context<Self>) -> Self {
48 let focus_handle = cx.focus_handle();
49
50 let initial_code = vec![
51 "// Rust sample code".to_string(),
52 "use std::collections::HashMap;".to_string(),
53 "".to_string(),
54 "fn main() {".to_string(),
55 " let mut count = 0;".to_string(),
56 " ".to_string(),
57 " // Count from 1 to 10".to_string(),
58 " for i in 1..=10 {".to_string(),
59 " count += i;".to_string(),
60 " }".to_string(),
61 " ".to_string(),
62 " // HashMap example".to_string(),
63 " let mut scores = HashMap::new();".to_string(),
64 " scores.insert(\"Blue\", 10);".to_string(),
65 " scores.insert(\"Yellow\", 50);".to_string(),
66 " ".to_string(),
67 " println!(\"Final count: {}\", count);".to_string(),
68 "}".to_string(),
69 ];
70
71 let mut editor = Editor::new("editor", initial_code);
72
73 let highlighter = SyntaxHighlighter::new();
74 let available_themes = highlighter.available_themes();
75
76 let default_theme_index = available_themes
77 .iter()
78 .position(|t| t == "base16-ocean.dark")
79 .unwrap_or(0);
80
81 editor.set_theme(&available_themes[default_theme_index]);
82
83 let available_languages = vec![
84 ("Rust".to_string(), "rs".to_string(), get_rust_sample()),
85 (
86 "Plain Text".to_string(),
87 "txt".to_string(),
88 get_plain_text_sample(),
89 ),
90 ];
91
92 editor.set_language("Rust".to_string());
93
94 Self {
95 focus_handle,
96 editor,
97 current_theme_index: default_theme_index,
98 available_themes,
99 current_language_index: 0,
100 available_languages,
101 }
102 }pub fn set_theme(&mut self, theme_name: &str)
Sourcepub fn available_themes(&self) -> Vec<String>
pub fn available_themes(&self) -> Vec<String>
Examples found in repository?
examples/editor_demo.rs (line 74)
47 fn new(cx: &mut Context<Self>) -> Self {
48 let focus_handle = cx.focus_handle();
49
50 let initial_code = vec![
51 "// Rust sample code".to_string(),
52 "use std::collections::HashMap;".to_string(),
53 "".to_string(),
54 "fn main() {".to_string(),
55 " let mut count = 0;".to_string(),
56 " ".to_string(),
57 " // Count from 1 to 10".to_string(),
58 " for i in 1..=10 {".to_string(),
59 " count += i;".to_string(),
60 " }".to_string(),
61 " ".to_string(),
62 " // HashMap example".to_string(),
63 " let mut scores = HashMap::new();".to_string(),
64 " scores.insert(\"Blue\", 10);".to_string(),
65 " scores.insert(\"Yellow\", 50);".to_string(),
66 " ".to_string(),
67 " println!(\"Final count: {}\", count);".to_string(),
68 "}".to_string(),
69 ];
70
71 let mut editor = Editor::new("editor", initial_code);
72
73 let highlighter = SyntaxHighlighter::new();
74 let available_themes = highlighter.available_themes();
75
76 let default_theme_index = available_themes
77 .iter()
78 .position(|t| t == "base16-ocean.dark")
79 .unwrap_or(0);
80
81 editor.set_theme(&available_themes[default_theme_index]);
82
83 let available_languages = vec![
84 ("Rust".to_string(), "rs".to_string(), get_rust_sample()),
85 (
86 "Plain Text".to_string(),
87 "txt".to_string(),
88 get_plain_text_sample(),
89 ),
90 ];
91
92 editor.set_language("Rust".to_string());
93
94 Self {
95 focus_handle,
96 editor,
97 current_theme_index: default_theme_index,
98 available_themes,
99 current_language_index: 0,
100 available_languages,
101 }
102 }pub fn detect_language( &self, text: &str, file_extension: Option<&str>, ) -> Option<String>
Sourcepub fn clear_state_from_line(&mut self, line_number: usize, language: &str)
pub fn clear_state_from_line(&mut self, line_number: usize, language: &str)
Clear cached highlighting state from a specific line onward. This is useful for incremental re-highlighting when text changes.
Sourcepub fn reset_state(&mut self)
pub fn reset_state(&mut self)
Reset all cached highlighting state. Call this when the buffer content has significantly changed.
pub fn highlight_line( &mut self, line: &str, language: &str, line_number: usize, font_family: SharedString, _font_size: f32, ) -> Vec<TextRun>
pub fn get_theme_background(&self) -> Hsla
pub fn get_theme_foreground(&self) -> Hsla
pub fn get_theme_gutter_background(&self) -> Hsla
pub fn get_theme_line_highlight(&self) -> Hsla
pub fn get_theme_selection(&self) -> Hsla
pub fn load_theme_from_file(&mut self, path: &str) -> Result<(), String>
pub fn load_syntax_from_file(&mut self, path: &str) -> Result<(), String>
Trait Implementations§
Source§impl Clone for SyntaxHighlighter
impl Clone for SyntaxHighlighter
Source§fn clone(&self) -> SyntaxHighlighter
fn clone(&self) -> SyntaxHighlighter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SyntaxHighlighter
impl !RefUnwindSafe for SyntaxHighlighter
impl !Send for SyntaxHighlighter
impl !Sync for SyntaxHighlighter
impl Unpin for SyntaxHighlighter
impl !UnwindSafe for SyntaxHighlighter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().