@@ -97,8 +97,7 @@ pub fn render_document(
97
97
doc : & Document ,
98
98
offset : ViewPosition ,
99
99
doc_annotations : & TextAnnotations ,
100
- syntax_highlight_iter : impl Iterator < Item = HighlightEvent > ,
101
- overlay_highlight_iter : impl Iterator < Item = HighlightEvent > ,
100
+ highlight_iter : impl Iterator < Item = HighlightEvent > ,
102
101
theme : & Theme ,
103
102
line_decoration : & mut [ Box < dyn LineDecoration + ' _ > ] ,
104
103
translated_positions : & mut [ TranslatedPosition ] ,
@@ -110,8 +109,7 @@ pub fn render_document(
110
109
offset,
111
110
& doc. text_format ( viewport. width , Some ( theme) ) ,
112
111
doc_annotations,
113
- syntax_highlight_iter,
114
- overlay_highlight_iter,
112
+ highlight_iter,
115
113
theme,
116
114
line_decoration,
117
115
translated_positions,
@@ -159,8 +157,7 @@ pub fn render_text<'t>(
159
157
offset : ViewPosition ,
160
158
text_fmt : & TextFormat ,
161
159
text_annotations : & TextAnnotations ,
162
- syntax_highlight_iter : impl Iterator < Item = HighlightEvent > ,
163
- overlay_highlight_iter : impl Iterator < Item = HighlightEvent > ,
160
+ highlight_iter : impl Iterator < Item = HighlightEvent > ,
164
161
theme : & Theme ,
165
162
line_decorations : & mut [ Box < dyn LineDecoration + ' _ > ] ,
166
163
translated_positions : & mut [ TranslatedPosition ] ,
@@ -181,16 +178,10 @@ pub fn render_text<'t>(
181
178
182
179
let ( mut formatter, mut first_visible_char_idx) =
183
180
DocumentFormatter :: new_at_prev_checkpoint ( text, text_fmt, text_annotations, offset. anchor ) ;
184
- let mut syntax_styles = StyleIter {
181
+ let mut styles = StyleIter {
185
182
text_style : renderer. text_style ,
186
183
active_highlights : Vec :: with_capacity ( 64 ) ,
187
- highlight_iter : syntax_highlight_iter,
188
- theme,
189
- } ;
190
- let mut overlay_styles = StyleIter {
191
- text_style : renderer. text_style ,
192
- active_highlights : Vec :: with_capacity ( 64 ) ,
193
- highlight_iter : overlay_highlight_iter,
184
+ highlight_iter,
194
185
theme,
195
186
} ;
196
187
@@ -202,10 +193,7 @@ pub fn render_text<'t>(
202
193
} ;
203
194
let mut is_in_indent_area = true ;
204
195
let mut last_line_indent_level = 0 ;
205
- let mut syntax_style_span = syntax_styles
206
- . next ( )
207
- . unwrap_or_else ( || ( Style :: default ( ) , usize:: MAX ) ) ;
208
- let mut overlay_style_span = overlay_styles
196
+ let mut style_span = styles
209
197
. next ( )
210
198
. unwrap_or_else ( || ( Style :: default ( ) , usize:: MAX ) ) ;
211
199
@@ -233,16 +221,9 @@ pub fn render_text<'t>(
233
221
234
222
// skip any graphemes on visual lines before the block start
235
223
if pos. row < row_off {
236
- if char_pos >= syntax_style_span. 1 {
237
- syntax_style_span = if let Some ( syntax_style_span) = syntax_styles. next ( ) {
238
- syntax_style_span
239
- } else {
240
- break ;
241
- }
242
- }
243
- if char_pos >= overlay_style_span. 1 {
244
- overlay_style_span = if let Some ( overlay_style_span) = overlay_styles. next ( ) {
245
- overlay_style_span
224
+ if char_pos >= style_span. 1 {
225
+ style_span = if let Some ( style_span) = styles. next ( ) {
226
+ style_span
246
227
} else {
247
228
break ;
248
229
}
@@ -279,15 +260,8 @@ pub fn render_text<'t>(
279
260
}
280
261
281
262
// acquire the correct grapheme style
282
- if char_pos >= syntax_style_span. 1 {
283
- syntax_style_span = syntax_styles
284
- . next ( )
285
- . unwrap_or ( ( Style :: default ( ) , usize:: MAX ) ) ;
286
- }
287
- if char_pos >= overlay_style_span. 1 {
288
- overlay_style_span = overlay_styles
289
- . next ( )
290
- . unwrap_or ( ( Style :: default ( ) , usize:: MAX ) ) ;
263
+ if char_pos >= style_span. 1 {
264
+ style_span = styles. next ( ) . unwrap_or ( ( Style :: default ( ) , usize:: MAX ) ) ;
291
265
}
292
266
char_pos += grapheme. doc_chars ( ) ;
293
267
@@ -301,25 +275,22 @@ pub fn render_text<'t>(
301
275
pos,
302
276
) ;
303
277
304
- let ( syntax_style, overlay_style) =
305
- if let GraphemeSource :: VirtualText { highlight } = grapheme. source {
306
- let mut style = renderer. text_style ;
307
- if let Some ( highlight) = highlight {
308
- style = style. patch ( theme. highlight ( highlight. 0 ) )
309
- }
310
- ( style, Style :: default ( ) )
278
+ let grapheme_style = if let GraphemeSource :: VirtualText { highlight } = grapheme. source {
279
+ let style = renderer. text_style ;
280
+ if let Some ( highlight) = highlight {
281
+ style. patch ( theme. highlight ( highlight. 0 ) )
311
282
} else {
312
- ( syntax_style_span. 0 , overlay_style_span. 0 )
313
- } ;
283
+ style
284
+ }
285
+ } else {
286
+ style_span. 0
287
+ } ;
314
288
315
- let is_virtual = grapheme. is_virtual ( ) ;
289
+ let virt = grapheme. is_virtual ( ) ;
316
290
renderer. draw_grapheme (
317
291
grapheme. grapheme ,
318
- GraphemeStyle {
319
- syntax_style,
320
- overlay_style,
321
- } ,
322
- is_virtual,
292
+ grapheme_style,
293
+ virt,
323
294
& mut last_line_indent_level,
324
295
& mut is_in_indent_area,
325
296
pos,
@@ -351,11 +322,6 @@ pub struct TextRenderer<'a> {
351
322
pub viewport : Rect ,
352
323
}
353
324
354
- pub struct GraphemeStyle {
355
- syntax_style : Style ,
356
- overlay_style : Style ,
357
- }
358
-
359
325
impl < ' a > TextRenderer < ' a > {
360
326
pub fn new (
361
327
surface : & ' a mut Surface ,
@@ -429,7 +395,7 @@ impl<'a> TextRenderer<'a> {
429
395
pub fn draw_grapheme (
430
396
& mut self ,
431
397
grapheme : Grapheme ,
432
- grapheme_style : GraphemeStyle ,
398
+ mut style : Style ,
433
399
is_virtual : bool ,
434
400
last_indent_level : & mut usize ,
435
401
is_in_indent_area : & mut bool ,
@@ -439,11 +405,9 @@ impl<'a> TextRenderer<'a> {
439
405
let is_whitespace = grapheme. is_whitespace ( ) ;
440
406
441
407
// TODO is it correct to apply the whitespace style to all unicode white spaces?
442
- let mut style = grapheme_style. syntax_style ;
443
408
if is_whitespace {
444
409
style = style. patch ( self . whitespace_style ) ;
445
410
}
446
- style = style. patch ( grapheme_style. overlay_style ) ;
447
411
448
412
let width = grapheme. width ( ) ;
449
413
let space = if is_virtual { " " } else { & self . space } ;
0 commit comments