From 5ee6ba5b38ebeb86006bb2e42734a2285eb354df Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Mon, 26 Jul 2021 10:51:00 -0700 Subject: [PATCH] Address some PR comments. --- helix-core/src/textobject.rs | 7 +++---- helix-view/src/view.rs | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/helix-core/src/textobject.rs b/helix-core/src/textobject.rs index e011c912a..b06bca5dd 100644 --- a/helix-core/src/textobject.rs +++ b/helix-core/src/textobject.rs @@ -32,10 +32,9 @@ fn find_word_boundary(slice: RopeSlice, mut pos: usize, direction: Direction) -> if category != prev_category && pos != 0 && pos != slice.len_chars() { return pos; } else { - if direction == Direction::Forward { - pos += 1; - } else { - pos = pos.saturating_sub(1); + match direction { + Direction::Forward => pos += 1, + Direction::Backward => pos = pos.saturating_sub(1), } prev_category = category; } diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index e90d0eab5..6b0c3c2af 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -92,17 +92,17 @@ impl View { let line = pos.row; let col = pos.col; let height = self.area.height.saturating_sub(1); // - 1 for statusline - let last_line = self.first_line + height as usize; + let last_line = (self.first_line + height as usize).saturating_sub(1); let scrolloff = PADDING.min(self.area.height as usize / 2); // TODO: user pref // TODO: not ideal const OFFSET: usize = 7; // 1 diagnostic + 5 linenr + 1 gutter - let last_col = self.first_col + (self.area.width as usize - OFFSET); + let last_col = (self.first_col + self.area.width as usize).saturating_sub(OFFSET + 1); - if line > last_line.saturating_sub(scrolloff + 1) { + if line > last_line.saturating_sub(scrolloff) { // scroll down - self.first_line += line - (last_line.saturating_sub(scrolloff + 1)); + self.first_line += line - (last_line.saturating_sub(scrolloff)); } else if line < self.first_line + scrolloff { // scroll up self.first_line = line.saturating_sub(scrolloff);