From d23a9a4aa3019a7c839f2cb4a2bb42b06d690039 Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:11:06 +0100 Subject: [PATCH 01/13] neovim like scroll function --- helix-term/src/commands.rs | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 07aef95d0ac4..0d13582f4484 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1501,6 +1501,57 @@ fn switch_to_lowercase(cx: &mut Context) { }); } +pub fn scroll_page_and_cursor(cx: &mut Context, offset: usize, direction: Direction) { + let config = cx.editor.config(); + let cursor_pos = cx.editor.cursor().0.unwrap(); + let (view, doc) = current!(cx.editor); + + let height = view.inner_height(); + let scrolloff = config.scrolloff.min(height.saturating_sub(1) / 2); + + let offset = match direction { + Direction::Forward => offset as isize, + Direction::Backward => -(offset as isize), + }; + + let doc_text = doc.text().slice(..); + let viewport = view.inner_area(doc); + let text_fmt = doc.text_format(viewport.width, None); + let mut annotations = view.text_annotations(doc, None); + + (view.offset.anchor, view.offset.vertical_offset) = char_idx_at_visual_offset( + doc_text, + view.offset.anchor, + view.offset.vertical_offset as isize + offset, + 0, + &text_fmt, + &annotations, + ); + + let movement = match cx.editor.mode { + Mode::Select => Movement::Extend, + _ => Movement::Move, + }; + + let mut offset = offset.abs() as usize; + if cursor_pos.row <= scrolloff { + offset += scrolloff - cursor_pos.row + 1; + } + + let selection = doc.selection(view.id).clone().transform(|range| { + move_vertically_visual( + doc_text, + range, + direction, + offset, + movement, + &text_fmt, + &mut annotations, + ) + }); + doc.set_selection(view.id, selection); +} + pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) { use Direction::*; let config = cx.editor.config(); From 1df3fefe55afc840d1ab5094b2116d1127fc363f Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:12:29 +0100 Subject: [PATCH 02/13] clear line annotations outside of move_vertically/_visual --- helix-core/src/movement.rs | 2 -- helix-term/src/commands.rs | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index 6c4f3f535f8d..8d5d2b995d4c 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -64,7 +64,6 @@ pub fn move_vertically_visual( if !text_fmt.soft_wrap { return move_vertically(slice, range, dir, count, behaviour, text_fmt, annotations); } - annotations.clear_line_annotations(); let pos = range.cursor(slice); // Compute the current position's 2d coordinates. @@ -112,7 +111,6 @@ pub fn move_vertically( text_fmt: &TextFormat, annotations: &mut TextAnnotations, ) -> Range { - annotations.clear_line_annotations(); let pos = range.cursor(slice); let line_idx = slice.char_to_line(pos); let line_start = slice.line_to_char(line_idx); diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 0d13582f4484..ba1975a298c5 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -595,6 +595,7 @@ fn move_impl(cx: &mut Context, move_fn: MoveFn, dir: Direction, behaviour: Movem let text = doc.text().slice(..); let text_fmt = doc.text_format(view.inner_area(doc).width, None); let mut annotations = view.text_annotations(doc, None); + annotations.clear_line_annotations(); let selection = doc.selection(view.id).clone().transform(|range| { move_fn( From db6db3e153d602186b1df5e28517f03ea091665f Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:19:09 +0100 Subject: [PATCH 03/13] add nvim scroll function to commands --- helix-term/src/commands.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index ba1975a298c5..010147203679 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -276,6 +276,10 @@ impl MappableCommand { page_down, "Move page down", half_page_up, "Move half page up", half_page_down, "Move half page down", + page_cursor_up, "Move page and cursor up", + page_cursor_down, "Move page and cursor down", + page_cursor_half_up, "Move page and cursor half up", + page_cursor_half_down, "Move page and cursor half down", select_all, "Select whole document", select_regex, "Select all regex matches inside selections", split_selection, "Split selections on regex matches", @@ -1654,6 +1658,30 @@ fn half_page_down(cx: &mut Context) { scroll(cx, offset, Direction::Forward); } +fn page_cursor_up(cx: &mut Context) { + let view = view!(cx.editor); + let offset = view.inner_height(); + scroll_page_and_cursor(cx, offset, Direction::Backward); +} + +fn page_cursor_down(cx: &mut Context) { + let view = view!(cx.editor); + let offset = view.inner_height(); + scroll_page_and_cursor(cx, offset, Direction::Forward); +} + +fn page_cursor_half_up(cx: &mut Context) { + let view = view!(cx.editor); + let offset = view.inner_height() / 2; + scroll_page_and_cursor(cx, offset, Direction::Backward); +} + +fn page_cursor_half_down(cx: &mut Context) { + let view = view!(cx.editor); + let offset = view.inner_height() / 2; + scroll_page_and_cursor(cx, offset, Direction::Forward); +} + #[allow(deprecated)] // currently uses the deprecated `visual_coords_at_pos`/`pos_at_visual_coords` functions // as this function ignores softwrapping (and virtual text) and instead only cares From 3d4038e5adef3bcc15a05b5cf736c43a09a9e418 Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:21:28 +0100 Subject: [PATCH 04/13] assign nvim-scroll to C-d and C-u (half page scrolls) --- helix-term/src/keymap/default.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 763ed4ae71ce..528ab966efac 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -178,8 +178,8 @@ pub fn default() -> HashMap { "esc" => normal_mode, "C-b" | "pageup" => page_up, "C-f" | "pagedown" => page_down, - "C-u" => half_page_up, - "C-d" => half_page_down, + "C-u" => page_cursor_half_up, + "C-d" => page_cursor_half_down, "C-w" => { "Window" "C-w" | "w" => rotate_view, @@ -287,8 +287,8 @@ pub fn default() -> HashMap { "j" | "down" => scroll_down, "C-b" | "pageup" => page_up, "C-f" | "pagedown" => page_down, - "C-u" | "backspace" => half_page_up, - "C-d" | "space" => half_page_down, + "C-u" => page_cursor_half_up, + "C-d" => page_cursor_half_down, "/" => search, "?" => rsearch, @@ -304,9 +304,8 @@ pub fn default() -> HashMap { "j" | "down" => scroll_down, "C-b" | "pageup" => page_up, "C-f" | "pagedown" => page_down, - "C-u" | "backspace" => half_page_up, - "C-d" | "space" => half_page_down, - + "C-u" => page_cursor_half_up, + "C-d" => page_cursor_half_down, "/" => search, "?" => rsearch, "n" => search_next, From 1fe59eae05796e38e4850f2a204ae4d868c3d36c Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Sun, 20 Aug 2023 12:06:35 +0100 Subject: [PATCH 05/13] dont remove backspace and space mapping --- helix-term/src/keymap/default.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 528ab966efac..92d6b5906a79 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -287,8 +287,8 @@ pub fn default() -> HashMap { "j" | "down" => scroll_down, "C-b" | "pageup" => page_up, "C-f" | "pagedown" => page_down, - "C-u" => page_cursor_half_up, - "C-d" => page_cursor_half_down, + "C-u" | "backspace" => page_cursor_half_up, + "C-d" | "space" => page_cursor_half_down, "/" => search, "?" => rsearch, @@ -304,8 +304,9 @@ pub fn default() -> HashMap { "j" | "down" => scroll_down, "C-b" | "pageup" => page_up, "C-f" | "pagedown" => page_down, - "C-u" => page_cursor_half_up, - "C-d" => page_cursor_half_down, + "C-u" | "backspace" => page_cursor_half_up, + "C-d" | "space" => page_cursor_half_down, + "/" => search, "?" => rsearch, "n" => search_next, From e4905729c338a2260e6981f1d8fac022897b4191 Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Mon, 21 Aug 2023 16:32:14 +0100 Subject: [PATCH 06/13] move non-softwrap logic to seperate function, call this in nvim-scroll fn --- helix-core/src/movement.rs | 23 +++++++++++++++++++++++ helix-term/src/commands.rs | 5 ++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index 8d5d2b995d4c..e9e529a5e3dc 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -64,6 +64,28 @@ pub fn move_vertically_visual( if !text_fmt.soft_wrap { return move_vertically(slice, range, dir, count, behaviour, text_fmt, annotations); } + annotations.clear_line_annotations(); + + return _move_vertically_visual( + slice, + range, + dir, + count, + behaviour, + text_fmt, + annotations, + ); +} + +pub fn _move_vertically_visual( + slice: RopeSlice, + range: Range, + dir: Direction, + count: usize, + behaviour: Movement, + text_fmt: &TextFormat, + annotations: &mut TextAnnotations +) -> Range { let pos = range.cursor(slice); // Compute the current position's 2d coordinates. @@ -111,6 +133,7 @@ pub fn move_vertically( text_fmt: &TextFormat, annotations: &mut TextAnnotations, ) -> Range { + annotations.clear_line_annotations(); let pos = range.cursor(slice); let line_idx = slice.char_to_line(pos); let line_start = slice.line_to_char(line_idx); diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 010147203679..dee4bb9993db 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -18,7 +18,7 @@ use helix_core::{ indent::IndentStyle, line_ending::{get_line_ending_of_str, line_end_char_index, str_is_line_ending}, match_brackets, - movement::{self, move_vertically_visual, Direction}, + movement::{self, move_vertically_visual, _move_vertically_visual, Direction}, object, pos_at_coords, regex::{self, Regex, RegexBuilder}, search::{self, CharMatcher}, @@ -599,7 +599,6 @@ fn move_impl(cx: &mut Context, move_fn: MoveFn, dir: Direction, behaviour: Movem let text = doc.text().slice(..); let text_fmt = doc.text_format(view.inner_area(doc).width, None); let mut annotations = view.text_annotations(doc, None); - annotations.clear_line_annotations(); let selection = doc.selection(view.id).clone().transform(|range| { move_fn( @@ -1544,7 +1543,7 @@ pub fn scroll_page_and_cursor(cx: &mut Context, offset: usize, direction: Direct } let selection = doc.selection(view.id).clone().transform(|range| { - move_vertically_visual( + _move_vertically_visual( doc_text, range, direction, From 3138951a5b417cf0a0ec13b6d22cdba4072780d0 Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:51:55 +0100 Subject: [PATCH 07/13] Revert "move non-softwrap logic to seperate function, call this in nvim-scroll fn" This reverts commit e4905729c338a2260e6981f1d8fac022897b4191. --- helix-core/src/movement.rs | 23 ----------------------- helix-term/src/commands.rs | 5 +++-- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index e9e529a5e3dc..8d5d2b995d4c 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -64,28 +64,6 @@ pub fn move_vertically_visual( if !text_fmt.soft_wrap { return move_vertically(slice, range, dir, count, behaviour, text_fmt, annotations); } - annotations.clear_line_annotations(); - - return _move_vertically_visual( - slice, - range, - dir, - count, - behaviour, - text_fmt, - annotations, - ); -} - -pub fn _move_vertically_visual( - slice: RopeSlice, - range: Range, - dir: Direction, - count: usize, - behaviour: Movement, - text_fmt: &TextFormat, - annotations: &mut TextAnnotations -) -> Range { let pos = range.cursor(slice); // Compute the current position's 2d coordinates. @@ -133,7 +111,6 @@ pub fn move_vertically( text_fmt: &TextFormat, annotations: &mut TextAnnotations, ) -> Range { - annotations.clear_line_annotations(); let pos = range.cursor(slice); let line_idx = slice.char_to_line(pos); let line_start = slice.line_to_char(line_idx); diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index dee4bb9993db..010147203679 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -18,7 +18,7 @@ use helix_core::{ indent::IndentStyle, line_ending::{get_line_ending_of_str, line_end_char_index, str_is_line_ending}, match_brackets, - movement::{self, move_vertically_visual, _move_vertically_visual, Direction}, + movement::{self, move_vertically_visual, Direction}, object, pos_at_coords, regex::{self, Regex, RegexBuilder}, search::{self, CharMatcher}, @@ -599,6 +599,7 @@ fn move_impl(cx: &mut Context, move_fn: MoveFn, dir: Direction, behaviour: Movem let text = doc.text().slice(..); let text_fmt = doc.text_format(view.inner_area(doc).width, None); let mut annotations = view.text_annotations(doc, None); + annotations.clear_line_annotations(); let selection = doc.selection(view.id).clone().transform(|range| { move_fn( @@ -1543,7 +1544,7 @@ pub fn scroll_page_and_cursor(cx: &mut Context, offset: usize, direction: Direct } let selection = doc.selection(view.id).clone().transform(|range| { - _move_vertically_visual( + move_vertically_visual( doc_text, range, direction, From 3cc3e2a489a7f880fa3ffae7fade441289f95778 Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:52:08 +0100 Subject: [PATCH 08/13] Revert "clear line annotations outside of move_vertically/_visual" This reverts commit 1df3fefe55afc840d1ab5094b2116d1127fc363f. --- helix-core/src/movement.rs | 2 ++ helix-term/src/commands.rs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index 8d5d2b995d4c..6c4f3f535f8d 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -64,6 +64,7 @@ pub fn move_vertically_visual( if !text_fmt.soft_wrap { return move_vertically(slice, range, dir, count, behaviour, text_fmt, annotations); } + annotations.clear_line_annotations(); let pos = range.cursor(slice); // Compute the current position's 2d coordinates. @@ -111,6 +112,7 @@ pub fn move_vertically( text_fmt: &TextFormat, annotations: &mut TextAnnotations, ) -> Range { + annotations.clear_line_annotations(); let pos = range.cursor(slice); let line_idx = slice.char_to_line(pos); let line_start = slice.line_to_char(line_idx); diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 010147203679..d5677d4d8799 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -599,7 +599,6 @@ fn move_impl(cx: &mut Context, move_fn: MoveFn, dir: Direction, behaviour: Movem let text = doc.text().slice(..); let text_fmt = doc.text_format(view.inner_area(doc).width, None); let mut annotations = view.text_annotations(doc, None); - annotations.clear_line_annotations(); let selection = doc.selection(view.id).clone().transform(|range| { move_fn( From 949cfb98fb72c29ee3f401d41ae3ae6d09c67669 Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Mon, 21 Aug 2023 18:12:20 +0100 Subject: [PATCH 09/13] add TODO for when inline diagnostics gets merged --- helix-term/src/commands.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d5677d4d8799..7abcee6638b4 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1542,6 +1542,10 @@ pub fn scroll_page_and_cursor(cx: &mut Context, offset: usize, direction: Direct offset += scrolloff - cursor_pos.row + 1; } + // TODO: When inline diagnostics gets merged- 1. move_vertically_visual removes + // line annotations/diagnostics so the cursor may jump further than the view. + // 2. If the cursor lands on a complete line of virtual text, the cursor will + // jump a different distance than the view. let selection = doc.selection(view.id).clone().transform(|range| { move_vertically_visual( doc_text, From 5a48de0800b4433cf1b8d9bb41bf74d1b5d3a11c Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Mon, 21 Aug 2023 20:48:53 +0100 Subject: [PATCH 10/13] move nvim-scroll logic into scroll(), dont respect scrolloff --- helix-term/src/commands.rs | 99 +++++++++++++------------------------ helix-term/src/ui/editor.rs | 2 +- 2 files changed, 35 insertions(+), 66 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7abcee6638b4..8359edd476c2 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1505,24 +1505,27 @@ fn switch_to_lowercase(cx: &mut Context) { }); } -pub fn scroll_page_and_cursor(cx: &mut Context, offset: usize, direction: Direction) { +pub fn scroll(cx: &mut Context, offset: usize, direction: Direction, sync_cursor: bool) { + use Direction::*; let config = cx.editor.config(); - let cursor_pos = cx.editor.cursor().0.unwrap(); let (view, doc) = current!(cx.editor); + let range = doc.selection(view.id).primary(); + let text = doc.text().slice(..); + + let cursor = range.cursor(text); let height = view.inner_height(); - let scrolloff = config.scrolloff.min(height.saturating_sub(1) / 2); + let scrolloff = config.scrolloff.min(height.saturating_sub(1) / 2); let offset = match direction { - Direction::Forward => offset as isize, - Direction::Backward => -(offset as isize), + Forward => offset as isize, + Backward => -(offset as isize), }; let doc_text = doc.text().slice(..); let viewport = view.inner_area(doc); let text_fmt = doc.text_format(viewport.width, None); let mut annotations = view.text_annotations(doc, None); - (view.offset.anchor, view.offset.vertical_offset) = char_idx_at_visual_offset( doc_text, view.offset.anchor, @@ -1532,64 +1535,30 @@ pub fn scroll_page_and_cursor(cx: &mut Context, offset: usize, direction: Direct &annotations, ); - let movement = match cx.editor.mode { - Mode::Select => Movement::Extend, - _ => Movement::Move, - }; - - let mut offset = offset.abs() as usize; - if cursor_pos.row <= scrolloff { - offset += scrolloff - cursor_pos.row + 1; - } - - // TODO: When inline diagnostics gets merged- 1. move_vertically_visual removes - // line annotations/diagnostics so the cursor may jump further than the view. - // 2. If the cursor lands on a complete line of virtual text, the cursor will - // jump a different distance than the view. - let selection = doc.selection(view.id).clone().transform(|range| { + if sync_cursor { + let movement = match cx.editor.mode { + Mode::Select => Movement::Extend, + _ => Movement::Move, + }; + // TODO: When inline diagnostics gets merged- 1. move_vertically_visual removes + // line annotations/diagnostics so the cursor may jump further than the view. + // 2. If the cursor lands on a complete line of virtual text, the cursor will + // jump a different distance than the view. + let selection = doc.selection(view.id).clone().transform(|range| { move_vertically_visual( doc_text, range, direction, - offset, + offset.abs() as usize, movement, &text_fmt, &mut annotations, ) }); - doc.set_selection(view.id, selection); -} - -pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) { - use Direction::*; - let config = cx.editor.config(); - let (view, doc) = current!(cx.editor); - - let range = doc.selection(view.id).primary(); - let text = doc.text().slice(..); - - let cursor = range.cursor(text); - let height = view.inner_height(); - - let scrolloff = config.scrolloff.min(height.saturating_sub(1) / 2); - let offset = match direction { - Forward => offset as isize, - Backward => -(offset as isize), - }; - - let doc_text = doc.text().slice(..); - let viewport = view.inner_area(doc); - let text_fmt = doc.text_format(viewport.width, None); - let annotations = view.text_annotations(doc, None); - (view.offset.anchor, view.offset.vertical_offset) = char_idx_at_visual_offset( - doc_text, - view.offset.anchor, - view.offset.vertical_offset as isize + offset, - 0, - &text_fmt, - &annotations, - ); - + doc.set_selection(view.id, selection); + return; + } + let mut head; match direction { Forward => { @@ -1640,49 +1609,49 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) { fn page_up(cx: &mut Context) { let view = view!(cx.editor); let offset = view.inner_height(); - scroll(cx, offset, Direction::Backward); + scroll(cx, offset, Direction::Backward, false); } fn page_down(cx: &mut Context) { let view = view!(cx.editor); let offset = view.inner_height(); - scroll(cx, offset, Direction::Forward); + scroll(cx, offset, Direction::Forward, false); } fn half_page_up(cx: &mut Context) { let view = view!(cx.editor); let offset = view.inner_height() / 2; - scroll(cx, offset, Direction::Backward); + scroll(cx, offset, Direction::Backward, false); } fn half_page_down(cx: &mut Context) { let view = view!(cx.editor); let offset = view.inner_height() / 2; - scroll(cx, offset, Direction::Forward); + scroll(cx, offset, Direction::Forward, false); } fn page_cursor_up(cx: &mut Context) { let view = view!(cx.editor); let offset = view.inner_height(); - scroll_page_and_cursor(cx, offset, Direction::Backward); + scroll(cx, offset, Direction::Backward, true); } fn page_cursor_down(cx: &mut Context) { let view = view!(cx.editor); let offset = view.inner_height(); - scroll_page_and_cursor(cx, offset, Direction::Forward); + scroll(cx, offset, Direction::Forward, true); } fn page_cursor_half_up(cx: &mut Context) { let view = view!(cx.editor); let offset = view.inner_height() / 2; - scroll_page_and_cursor(cx, offset, Direction::Backward); + scroll(cx, offset, Direction::Backward, true); } fn page_cursor_half_down(cx: &mut Context) { let view = view!(cx.editor); let offset = view.inner_height() / 2; - scroll_page_and_cursor(cx, offset, Direction::Forward); + scroll(cx, offset, Direction::Forward, true); } #[allow(deprecated)] @@ -5027,11 +4996,11 @@ fn align_view_middle(cx: &mut Context) { } fn scroll_up(cx: &mut Context) { - scroll(cx, cx.count(), Direction::Backward); + scroll(cx, cx.count(), Direction::Backward, false); } fn scroll_down(cx: &mut Context) { - scroll(cx, cx.count(), Direction::Forward); + scroll(cx, cx.count(), Direction::Forward, false); } fn goto_ts_object_impl(cx: &mut Context, object: &'static str, direction: Direction) { diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index aa159d40dce5..a8eb0dc33824 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -1139,7 +1139,7 @@ impl EditorView { } let offset = config.scroll_lines.unsigned_abs(); - commands::scroll(cxt, offset, direction); + commands::scroll(cxt, offset, direction, false); cxt.editor.tree.focus = current_view; cxt.editor.ensure_cursor_in_view(current_view); From 8563f4b277439afc63f944c8c54218c10d18b58f Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Mon, 21 Aug 2023 21:21:17 +0100 Subject: [PATCH 11/13] run cargo fmt --- helix-term/src/commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 8359edd476c2..aabfdf193689 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1542,7 +1542,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction, sync_cursor }; // TODO: When inline diagnostics gets merged- 1. move_vertically_visual removes // line annotations/diagnostics so the cursor may jump further than the view. - // 2. If the cursor lands on a complete line of virtual text, the cursor will + // 2. If the cursor lands on a complete line of virtual text, the cursor will // jump a different distance than the view. let selection = doc.selection(view.id).clone().transform(|range| { move_vertically_visual( @@ -1558,7 +1558,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction, sync_cursor doc.set_selection(view.id, selection); return; } - + let mut head; match direction { Forward => { From 2004525d461b0d6250b93e35ef238180046bcad9 Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Mon, 21 Aug 2023 22:01:27 +0100 Subject: [PATCH 12/13] run cargo clippy --- helix-term/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index aabfdf193689..442b6839d22f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1549,7 +1549,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction, sync_cursor doc_text, range, direction, - offset.abs() as usize, + offset.unsigned_abs(), movement, &text_fmt, &mut annotations, From e67355cc613cd285c40993a77f3be06699095905 Mon Sep 17 00:00:00 2001 From: alexanderdickie <75994927+AlexanderDickie@users.noreply.github.com> Date: Tue, 29 Aug 2023 21:11:25 +0100 Subject: [PATCH 13/13] update documenation for Ctrl-d and Ctrl-u remap --- book/src/keymap.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/book/src/keymap.md b/book/src/keymap.md index 0f41b3247f3d..bb4bbc3aebae 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -53,8 +53,8 @@ Normal mode is the default mode when you launch helix. Return to it from other m | `End` | Move to the end of the line | `goto_line_end` | | `Ctrl-b`, `PageUp` | Move page up | `page_up` | | `Ctrl-f`, `PageDown` | Move page down | `page_down` | -| `Ctrl-u` | Move half page up | `half_page_up` | -| `Ctrl-d` | Move half page down | `half_page_down` | +| `Ctrl-u` | Move cursor and page half page up | `page_cursor_half_up` | +| `Ctrl-d` | Move cursor and page half page down | `page_cursor_half_down` | | `Ctrl-i` | Jump forward on the jumplist | `jump_forward` | | `Ctrl-o` | Jump backward on the jumplist | `jump_backward` | | `Ctrl-s` | Save the current selection to the jumplist | `save_selection` | @@ -182,18 +182,18 @@ normal mode) is persistent and can be exited using the escape key. This is useful when you're simply looking over text and not actively editing it. -| Key | Description | Command | -| ----- | ----------- | ------- | -| `z`, `c` | Vertically center the line | `align_view_center` | -| `t` | Align the line to the top of the screen | `align_view_top` | -| `b` | Align the line to the bottom of the screen | `align_view_bottom` | -| `m` | Align the line to the middle of the screen (horizontally) | `align_view_middle` | -| `j`, `down` | Scroll the view downwards | `scroll_down` | -| `k`, `up` | Scroll the view upwards | `scroll_up` | -| `Ctrl-f`, `PageDown` | Move page down | `page_down` | -| `Ctrl-b`, `PageUp` | Move page up | `page_up` | -| `Ctrl-d` | Move half page down | `half_page_down` | -| `Ctrl-u` | Move half page up | `half_page_up` | +| Key | Description | Command | +| ----- | ----------- | ------- | +| `z`, `c` | Vertically center the line | `align_view_center` | +| `t` | Align the line to the top of the screen | `align_view_top` | +| `b` | Align the line to the bottom of the screen | `align_view_bottom` | +| `m` | Align the line to the middle of the screen (horizontally) | `align_view_middle` | +| `j`, `down` | Scroll the view downwards | `scroll_down` | +| `k`, `up` | Scroll the view upwards | `scroll_up` | +| `Ctrl-f`, `PageDown` | Move page down | `page_down` | +| `Ctrl-b`, `PageUp` | Move page up | `page_up` | +| `Ctrl-u` | Move cursor and page half page up | `page_cursor_half_up` | +| `Ctrl-d` | Move cursor and page half page down | `page_cursor_half_down` | #### Goto mode