@@ -37,6 +37,7 @@ pub struct Editor {
3737 id : Id ,
3838 read_only : bool ,
3939 display : ConfiguredDisplay ,
40+ highlight : highlight:: Cache ,
4041 text : String ,
4142 colors : SchemeColors ,
4243 selection : SelectionHelper ,
@@ -56,6 +57,7 @@ impl Default for Editor {
5657 id : Id :: default ( ) ,
5758 read_only : false ,
5859 display : ConfiguredDisplay :: new ( TextClass :: Editor , false ) ,
60+ highlight : Default :: default ( ) ,
5961 text : Default :: default ( ) ,
6062 colors : SchemeColors :: default ( ) ,
6163 selection : Default :: default ( ) ,
@@ -99,8 +101,8 @@ impl<S: ToString> From<S> for Editor {
99101/// support scrolling of text content. Since this component is not a widget it
100102/// cannot implement [`Viewport`] directly, but it does provide the following
101103/// methods: [`Self::content_size`], [`Self::draw_with_offset`].
102- #[ autoimpl ( Debug where H : trait ) ]
103- pub struct Component < H : Highlighter > ( pub Editor , highlight :: Text < H > ) ;
104+ #[ derive ( Debug , Default ) ]
105+ pub struct Component < H : Highlighter > ( pub Editor , H ) ;
104106
105107impl < H : Highlighter > Deref for Component < H > {
106108 type Target = ConfiguredDisplay ;
@@ -141,30 +143,23 @@ impl<H: Highlighter> Layout for Component<H> {
141143 }
142144}
143145
144- impl < H : Default + Highlighter > Default for Component < H > {
145- #[ inline]
146- fn default ( ) -> Self {
147- Component ( Editor :: default ( ) , Default :: default ( ) )
148- }
149- }
150-
151- impl < H : Default + Highlighter , S : ToString > From < S > for Component < H > {
146+ impl < H : Highlighter + Default , S : ToString > From < S > for Component < H > {
152147 #[ inline]
153148 fn from ( text : S ) -> Self {
154- Component ( Editor :: from ( text) , Default :: default ( ) )
149+ Component ( Editor :: from ( text) , H :: default ( ) )
155150 }
156151}
157152
158153impl < H : Highlighter > Component < H > {
159154 /// Replace the highlighter
160155 #[ inline]
161156 pub fn with_highlighter < H2 : Highlighter > ( self , highlighter : H2 ) -> Component < H2 > {
162- Component ( self . 0 , highlight :: Text :: new ( highlighter) )
157+ Component ( self . 0 , highlighter)
163158 }
164159
165160 /// Set a new highlighter of the same type
166161 pub fn set_highlighter ( & mut self , highlighter : H ) {
167- self . 1 = highlight :: Text :: new ( highlighter) ;
162+ self . 1 = highlighter;
168163 }
169164
170165 /// Get the background color
@@ -210,11 +205,12 @@ impl<H: Highlighter> Component<H> {
210205 #[ inline]
211206 fn prepare_runs ( & mut self ) {
212207 fn inner < H : Highlighter > ( this : & mut Component < H > ) {
213- this. 1 . highlight ( & this. 0 . text ) ;
208+ this. 0 . highlight . highlight ( & this. 0 . text , & mut this . 1 ) ;
214209 let ( dpem, font) = ( this. 0 . display . font_size ( ) , this. 0 . display . font ( ) ) ;
215- this. 0
216- . display
217- . prepare_runs ( this. 0 . text . as_str ( ) , this. 1 . font_tokens ( dpem, font) ) ;
210+ this. 0 . display . prepare_runs (
211+ this. 0 . text . as_str ( ) ,
212+ this. 0 . highlight . font_tokens ( dpem, font) ,
213+ ) ;
218214 }
219215
220216 if self . 0 . display . status ( ) < Status :: LevelRuns {
@@ -307,7 +303,7 @@ impl<H: Highlighter> Component<H> {
307303 let pos = self . rect ( ) . pos - offset;
308304 let range: Range < u32 > = self . 0 . selection . range ( ) . cast ( ) ;
309305
310- let color_tokens = self . 1 . color_tokens ( ) ;
306+ let color_tokens = self . 0 . highlight . color_tokens ( ) ;
311307 let default_colors = format:: Colors {
312308 foreground : self . 0 . colors . foreground ,
313309 background : None ,
@@ -391,7 +387,7 @@ impl<H: Highlighter> Component<H> {
391387 } ;
392388 draw. text ( pos, rect, display, tokens) ;
393389
394- let decorations = self . 1 . decorations ( ) ;
390+ let decorations = self . 0 . highlight . decorations ( ) ;
395391 if !decorations. is_empty ( ) {
396392 draw. decorate_text ( pos, rect, display, decorations) ;
397393 }
0 commit comments