diff options
author | Blaž Hrastnik | 2021-07-29 09:43:20 +0000 |
---|---|---|
committer | GitHub | 2021-07-29 09:43:20 +0000 |
commit | 05d20e196f81c8b71c2aecaf46f5d443d6b6b582 (patch) | |
tree | 0642d43c12f16ac3c68c19602c64fdea8108cc97 /helix-view/src/view.rs | |
parent | 8a2fa692f26f5bff5861151f395304837f5d93ec (diff) | |
parent | e4d41d06e3b52863d35ce3703f78cc8e0807c504 (diff) |
Merge pull request #376 from cessen/great_line_ending_and_cursor_range_cleanup
The Great Line Ending & Cursor Range Cleanup
Diffstat (limited to 'helix-view/src/view.rs')
-rw-r--r-- | helix-view/src/view.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 24df7a4f..6b0c3c2a 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -84,18 +84,21 @@ impl View { } pub fn ensure_cursor_in_view(&mut self, doc: &Document) { - let cursor = doc.selection(self.id).cursor(); + let cursor = doc + .selection(self.id) + .primary() + .cursor(doc.text().slice(..)); let pos = coords_at_pos(doc.text().slice(..), cursor); 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) { // scroll down @@ -119,8 +122,9 @@ impl View { pub fn last_line(&self, doc: &Document) -> usize { let height = self.area.height.saturating_sub(1); // - 1 for statusline std::cmp::min( - self.first_line + height as usize, - doc.text().len_lines() - 1, + // Saturating subs to make it inclusive zero indexing. + (self.first_line + height as usize).saturating_sub(1), + doc.text().len_lines().saturating_sub(1), ) } |