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-term | |
parent | c6456d04b9f16ed8f5ad0f256a38218b514de5dc (diff) |
minor: Simplify some code.
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c2865007..c3ec49df 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -201,18 +201,6 @@ pub fn extend_next_word_end(cx: &mut Context) { doc.set_selection(selection); } -pub fn check_cursor_in_view(view: &View) -> bool { - let doc = &view.doc; - let cursor = doc.selection().cursor(); - let line = doc.text().char_to_line(cursor); - let document_end = view.first_line + view.area.height.saturating_sub(1) as usize; - - if (line > document_end.saturating_sub(PADDING)) || (line < view.first_line + PADDING) { - return false; - } - true -} - pub fn page_up(cx: &mut Context) { let view = cx.view(); if view.first_line < PADDING { @@ -221,7 +209,7 @@ pub fn page_up(cx: &mut Context) { view.first_line = view.first_line.saturating_sub(view.area.height as usize); - if !check_cursor_in_view(view) { + if !view.check_cursor_in_view() { let text = view.doc.text(); let pos = text.line_to_char(view.last_line().saturating_sub(PADDING)); view.doc.set_selection(Selection::point(pos)); @@ -249,7 +237,7 @@ pub fn half_page_up(cx: &mut Context) { .first_line .saturating_sub(view.area.height as usize / 2); - if !check_cursor_in_view(view) { + if !view.check_cursor_in_view() { let text = &view.doc.text(); let pos = text.line_to_char(view.last_line() - PADDING); view.doc.set_selection(Selection::point(pos)); @@ -262,7 +250,7 @@ pub fn half_page_down(cx: &mut Context) { if view.first_line < lines.saturating_sub(view.area.height as usize) { view.first_line += view.area.height as usize / 2; } - if !check_cursor_in_view(view) { + if !view.check_cursor_in_view() { let text = view.doc.text(); let pos = text.line_to_char(view.first_line as usize); view.doc.set_selection(Selection::point(pos)); |