From 16212eaf52657ea47bba7add7deac378d0bf4b4a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 28 Jul 2024 23:59:51 +0200 Subject: Simplify `highlight` method for `text_editor` widget --- widget/src/text_editor.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'widget/src') 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, + { + self.highlight_with::( + 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( + pub fn highlight_with( self, settings: H::Settings, to_format: fn( -- cgit