SyntaxHighlighter

Struct SyntaxHighlighter 

Source
pub struct SyntaxHighlighter { /* private fields */ }

Implementations§

Source§

impl SyntaxHighlighter

Source

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    }
Source

pub fn set_theme(&mut self, theme_name: &str)

Source

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    }
Source

pub fn detect_language( &self, text: &str, file_extension: Option<&str>, ) -> Option<String>

Source

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.

Source

pub fn reset_state(&mut self)

Reset all cached highlighting state. Call this when the buffer content has significantly changed.

Source

pub fn highlight_line( &mut self, line: &str, language: &str, line_number: usize, font_family: SharedString, _font_size: f32, ) -> Vec<TextRun>

Source

pub fn get_theme_background(&self) -> Hsla

Source

pub fn get_theme_foreground(&self) -> Hsla

Source

pub fn get_theme_gutter_background(&self) -> Hsla

Source

pub fn get_theme_line_highlight(&self) -> Hsla

Source

pub fn get_theme_selection(&self) -> Hsla

Source

pub fn load_theme_from_file(&mut self, path: &str) -> Result<(), String>

Source

pub fn load_syntax_from_file(&mut self, path: &str) -> Result<(), String>

Trait Implementations§

Source§

impl Clone for SyntaxHighlighter

Source§

fn clone(&self) -> SyntaxHighlighter

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for SyntaxHighlighter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

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().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more