diff options
author | Blaž Hrastnik | 2021-02-24 07:07:39 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-02-24 07:07:39 +0000 |
commit | 87a6d4e73615e17559b99afa065799a38fe6c39e (patch) | |
tree | 23e437304421ec88a355e3ef887cf6cb4a322591 /helix-view/src/view.rs | |
parent | c6456d04b9f16ed8f5ad0f256a38218b514de5dc (diff) |
minor: Simplify some code.
Diffstat (limited to 'helix-view/src/view.rs')
-rw-r--r-- | helix-view/src/view.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index e02436b3..f3d92bfd 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -35,6 +35,17 @@ impl View { Ok(view) } + pub fn check_cursor_in_view(&self) -> bool { + let cursor = self.doc.selection().cursor(); + let line = self.doc.text().char_to_line(cursor); + let document_end = self.first_line + self.area.height.saturating_sub(1) as usize; + + if (line > document_end.saturating_sub(PADDING)) || (line < self.first_line + PADDING) { + return false; + } + true + } + pub fn ensure_cursor_in_view(&mut self) { let cursor = self.doc.state.selection().cursor(); let line = self.doc.text().char_to_line(cursor); |