From 978f5114d82b51f2327c08faf2bf692181bf2408 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 9 Apr 2021 18:48:56 +0900 Subject: Horizontal scrolling! It only took a year to get around to it. --- helix-term/src/ui/editor.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'helix-term/src/ui') diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 5426e014..d32f7864 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -189,18 +189,20 @@ impl EditorView { } else if grapheme == "\t" { visual_x += (tab_width as u16); } else { - if visual_x >= viewport.width { - // if we're offscreen just keep going until we hit a new line - // TODO: will need tweaking when we also take into account - // horizontal scrolling - continue; - } + let out_of_bounds = visual_x < view.first_col as u16 + || visual_x >= viewport.width + view.first_col as u16; // Cow will prevent allocations if span contained in a single slice // which should really be the majority case let grapheme = Cow::from(grapheme); let width = grapheme_width(&grapheme) as u16; + if out_of_bounds { + // if we're offscreen just keep going until we hit a new line + visual_x += width; + continue; + } + // ugh,interleave highlight spans with diagnostic spans let is_diagnostic = doc.diagnostics.iter().any(|diagnostic| { diagnostic.range.start <= char_index @@ -214,7 +216,7 @@ impl EditorView { }; surface.set_string( - viewport.x + visual_x, + viewport.x + visual_x - view.first_col as u16, viewport.y + line, grapheme, style, -- cgit v1.2.3-70-g09d2