aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-04-24 02:46:46 +0000
committerBlaž Hrastnik2021-04-24 02:46:46 +0000
commit594575ba3f1cd1775f104c95ce604f952ccd5caf (patch)
treef2344735f870beb7c1a28482af1d7a44e45eb9b4 /helix-term/src
parent651d3dec83144896d2ae7a2a547b1c5c3807a6b3 (diff)
Center forward and backward jumps too.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs16
1 files changed, 11 insertions, 5 deletions
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);
};
}