@@ -245,15 +245,10 @@ impl EditorView {
245245 acc.patch(style)
246246 });
247247
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
254248 for grapheme in RopeGraphemes::new(text) {
255249 let out_of_bounds = visual_x < view.first_col as u16
256250 || visual_x >= viewport.width + view.first_col as u16;
251+
257252 if LineEnding::from_rope_slice(&grapheme).is_some() {
258253 if !out_of_bounds {
259254 // we still want to render an empty cell with the style
@@ -272,42 +267,30 @@ impl EditorView {
272267 if line >= viewport.height {
273268 break 'outer;
274269 }
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);
291270 } else {
292− // Cow will prevent allocations if span contained in a single slice
293− // which should really be the majority case
294271 let grapheme = Cow::from(grapheme);
295− let width = grapheme_width(&grapheme) as u16;
296272
297− if out_of_bounds {
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+
283+ if !out_of_bounds {
298284 // if we're offscreen just keep going until we hit a new line
299− visual_x = visual_x.saturating_add(width);
300− continue;
285+ surface.set_string(
286+ viewport.x + visual_x - view.first_col as u16,
287+ viewport.y + line,
288+ grapheme,
289+ style,
290+ );
301291 }
302292
303− surface.set_string(
304− viewport.x + visual_x - view.first_col as u16,
305− viewport.y + line,
306− grapheme,
307− style,
308− );
309−
310− visual_x += width;
293+ visual_x = visual_x.saturating_add(width as u16);
311294 }
312295 }
313296 }