From 594575ba3f1cd1775f104c95ce604f952ccd5caf Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sat, 24 Apr 2021 11:46:46 +0900 Subject: Center forward and backward jumps too. --- helix-term/src/commands.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c1471cef..b77e205f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1889,12 +1889,16 @@ pub fn match_brackets(cx: &mut Context) { pub fn jump_forward(cx: &mut Context) { let count = cx.count; - let view = cx.view(); + let (view, doc) = cx.current(); if let Some((id, selection)) = view.jumps.forward(count) { - // TODO: position first_line so that main cursor is centered - view.first_line = 0; view.doc = *id; + let selection = selection.clone(); + let cursor = selection.cursor(); + doc.set_selection(view.id, selection); + // TODO: extract this centering into a function to share with _goto? + let line = doc.text().char_to_line(cursor); + view.first_line = line.saturating_sub(view.area.height as usize / 2); }; } @@ -1903,11 +1907,13 @@ pub fn jump_backward(cx: &mut Context) { let (view, doc) = cx.current(); if let Some((id, selection)) = view.jumps.backward(count) { - // TODO: position first_line so that main cursor is centered - view.first_line = 0; view.doc = *id; let selection = selection.clone(); + let cursor = selection.cursor(); doc.set_selection(view.id, selection); + // TODO: extract this centering into a function to share with _goto? + let line = doc.text().char_to_line(cursor); + view.first_line = line.saturating_sub(view.area.height as usize / 2); }; } -- cgit v1.2.3-70-g09d2