on master help sign in
Merge tab & char rendering code
bcca152Blaž Hrastnik
helix-term/src/ui/editor.rs+19−36
@@ -245,15 +245,10 @@ impl EditorView {
245 acc.patch(style)
245 acc.patch(style)
246 });
246 });
247
247
248− // TODO: we could render the text to a surface, then cache that, that
249− // way if only the selection/cursor changes we can copy from cache
250− // and paint the new cursor.
251− // We could keep a single resizable surface on the View for that.
252−
253− // iterate over range char by char
254 for grapheme in RopeGraphemes::new(text) {
248 for grapheme in RopeGraphemes::new(text) {
255 let out_of_bounds = visual_x < view.first_col as u16
249 let out_of_bounds = visual_x < view.first_col as u16
256 || visual_x >= viewport.width + view.first_col as u16;
250 || visual_x >= viewport.width + view.first_col as u16;
251+
257 if LineEnding::from_rope_slice(&grapheme).is_some() {
252 if LineEnding::from_rope_slice(&grapheme).is_some() {
258 if !out_of_bounds {
253 if !out_of_bounds {
259 // we still want to render an empty cell with the style
254 // we still want to render an empty cell with the style
@@ -272,42 +267,30 @@ impl EditorView {
272 if line >= viewport.height {
267 if line >= viewport.height {
273 break 'outer;
268 break 'outer;
274 }
269 }
275− } else if grapheme == "\t" {
276− if out_of_bounds {
277− // if we're offscreen just keep going until we hit a new line
278− visual_x = visual_x.saturating_add(tab_width as u16);
279− continue;
280− }
281−
282− // we still want to render an empty cell with the style
283− surface.set_string(
284− viewport.x + visual_x - view.first_col as u16,
285− viewport.y + line,
286− &tab,
287− style,
288− );
289−
290− visual_x = visual_x.saturating_add(tab_width as u16);
291 } else {
270 } else {
292− // Cow will prevent allocations if span contained in a single slice
293− // which should really be the majority case
294 let grapheme = Cow::from(grapheme);
271 let grapheme = Cow::from(grapheme);
295− let width = grapheme_width(&grapheme) as u16;
296
272
273+ let (grapheme, width) = if grapheme == "\t" {
274+ // make sure we display tab as appropriate amount of spaces
275+ (tab.as_str(), tab_width)
276+ } else {
277+ // Cow will prevent allocations if span contained in a single slice
278+ // which should really be the majority case
279+ let width = grapheme_width(&grapheme);
280+ (grapheme.as_ref(), width)
281+ };
282+
297− if out_of_bounds {
283+ if !out_of_bounds {
298 // if we're offscreen just keep going until we hit a new line
284 // if we're offscreen just keep going until we hit a new line
299− visual_x = visual_x.saturating_add(width);
285+ surface.set_string(
300− continue;
286+ viewport.x + visual_x - view.first_col as u16,
287+ viewport.y + line,
288+ grapheme,
289+ style,
290+ );
301 }
291 }
302
292
303− surface.set_string(
293+ visual_x = visual_x.saturating_add(width as u16);
304− viewport.x + visual_x - view.first_col as u16,
305− viewport.y + line,
306− grapheme,
307− style,
308− );
309−
310− visual_x += width;
311 }
294 }
312 }
295 }
313 }
296 }