From 1750ac8e76ca04e6ed7cd0ae871ea6ffe15999a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Vald=C3=A9s?= Date: Mon, 3 Feb 2020 20:46:51 +0100 Subject: [PATCH] Fix scrolling issue introduced when extracting the grid --- src/editor/grid.rs | 9 ++++++--- src/editor/mod.rs | 9 ++------- src/renderer/cursor_renderer.rs | 3 +-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/editor/grid.rs b/src/editor/grid.rs index 9a71443..22649a6 100644 --- a/src/editor/grid.rs +++ b/src/editor/grid.rs @@ -15,14 +15,17 @@ pub struct CharacterGrid { } impl CharacterGrid { - pub fn new() -> CharacterGrid { - CharacterGrid { + pub fn new(size: (u64, u64)) -> CharacterGrid { + let mut result = CharacterGrid { characters: vec![], dirty: vec![], width: 0, height: 0, should_clear: true, - } + }; + + result.resize(size.0, size.1); + result } pub fn resize(&mut self, width: u64, height: u64) { diff --git a/src/editor/mod.rs b/src/editor/mod.rs index c7310cc..b090a1e 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -33,7 +33,6 @@ pub struct DrawCommand { pub struct Editor { pub grid: CharacterGrid, pub title: String, - pub size: (u64, u64), pub font_name: Option, pub font_size: Option, pub cursor: Cursor, @@ -45,10 +44,8 @@ pub struct Editor { impl Editor { pub fn new() -> Editor { let mut editor = Editor { - grid: CharacterGrid::new(), - + grid: CharacterGrid::new(INITIAL_DIMENSIONS), title: "Neovide".to_string(), - size: INITIAL_DIMENSIONS, font_name: None, font_size: None, cursor: Cursor::new(), @@ -216,11 +213,9 @@ impl Editor { Box::new((top as i64 .. (bot as i64 + rows)).rev()) }; - let (_, height) = self.size; - for y in y_iter { let dest_y = y - rows; - if dest_y >= 0 && dest_y < height as i64 { + if dest_y >= 0 && dest_y < self.grid.height as i64 { let x_iter : Box> = if cols > 0 { Box::new((left as i64 + cols) .. right as i64) diff --git a/src/renderer/cursor_renderer.rs b/src/renderer/cursor_renderer.rs index 3649075..f29b95e 100644 --- a/src/renderer/cursor_renderer.rs +++ b/src/renderer/cursor_renderer.rs @@ -182,8 +182,7 @@ impl CursorRenderer { let editor = EDITOR.lock().unwrap(); let (_, grid_y) = cursor.position; let (_, previous_y) = self.previous_position; - let (_, height) = editor.size; - if grid_y == height - 1 && previous_y != grid_y { + if grid_y == editor.grid.height - 1 && previous_y != grid_y { self.command_line_delay = self.command_line_delay + 1; if self.command_line_delay < COMMAND_LINE_DELAY_FRAMES { self.previous_position