From 1503589355a5b9f1697e08340dd281bf0b209d6b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 19 Oct 2022 15:12:47 -0600 Subject: [PATCH] Fix insert at end of line --- src/buffer.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/buffer.rs b/src/buffer.rs index ea37355..393214e 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -118,7 +118,7 @@ impl<'a> TextBuffer<'a> { ) -> Self { Self { font_matches, - text_lines: Vec::new(), + text_lines: vec![String::new()], // Must have one line shape_lines: Vec::new(), layout_lines: Vec::new(), metrics, @@ -415,6 +415,21 @@ impl<'a> TextBuffer<'a> { text_line.insert(insert_i, character); self.cursor.glyph += 1; self.reshape_line(line.line_i); + + if self.cursor.glyph > self.layout_lines[self.cursor.line].glyphs.len() { + if self.cursor.line + 1 < self.layout_lines.len() { + self.cursor.glyph -= self.layout_lines[self.cursor.line].glyphs.len(); + self.cursor.line += 1; + + let lines = self.lines(); + if (self.cursor.line as i32) < self.scroll + || (self.cursor.line as i32) >= self.scroll + lines + { + self.scroll = self.cursor.line as i32 - (lines - 1); + self.shape_until_scroll(); + } + } + } }, TextAction::Enter => { {