diff options
author | 2024-07-28 23:59:51 +0200 | |
---|---|---|
committer | 2024-07-28 23:59:51 +0200 | |
commit | 16212eaf52657ea47bba7add7deac378d0bf4b4a (patch) | |
tree | 27feb673ab07016a48ee1ae491fa7331a349cabb /widget | |
parent | 1aa0a8fa0d8e5dfe9ab09a11ea7c69f71e19795b (diff) | |
download | iced-16212eaf52657ea47bba7add7deac378d0bf4b4a.tar.gz iced-16212eaf52657ea47bba7add7deac378d0bf4b4a.tar.bz2 iced-16212eaf52657ea47bba7add7deac378d0bf4b4a.zip |
Simplify `highlight` method for `text_editor` widget
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/text_editor.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 56fb7578..b5092012 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -13,7 +13,7 @@ use crate::core::text::{self, LineHeight, Text}; use crate::core::widget::operation; use crate::core::widget::{self, Widget}; use crate::core::{ - Background, Border, Color, Element, Length, Padding, Pixels, Point, + self, Background, Border, Color, Element, Length, Padding, Pixels, Point, Rectangle, Shell, Size, SmolStr, Theme, Vector, }; @@ -146,9 +146,28 @@ where self } + /// Highlights the [`TextEditor`] using the given syntax and theme. + #[cfg(feature = "highlighter")] + pub fn highlight( + self, + syntax: &str, + theme: iced_highlighter::Theme, + ) -> TextEditor<'a, iced_highlighter::Highlighter, Message, Theme, Renderer> + where + Renderer: text::Renderer<Font = core::Font>, + { + self.highlight_with::<iced_highlighter::Highlighter>( + iced_highlighter::Settings { + theme, + token: syntax.to_owned(), + }, + |highlight, _theme| highlight.to_format(), + ) + } + /// Highlights the [`TextEditor`] with the given [`Highlighter`] and /// a strategy to turn its highlights into some text format. - pub fn highlight<H: text::Highlighter>( + pub fn highlight_with<H: text::Highlighter>( self, settings: H::Settings, to_format: fn( |