aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorNarazaki Shuji2022-12-06 02:16:08 +0000
committerGitHub2022-12-06 02:16:08 +0000
commit453a75a3739338348024b6c676231aef9ef6cb7b (patch)
treebf7d60723458b34d706f3b5a66263f267b4acba6 /helix-term/src
parent952f292d252bdc135f10b1ffa52734d5242d2c60 (diff)
fix: align view after jumplist_picker (#3743)
* Add `View::ensure_cursor_in_view_center` to adjust view after searching and jumping Also `offset_coodrs_to_in_view` was refactored to reduce duplicated position calculations. * Fix a wrong offset calculation in `offset_coords_to_in_view_center` It ignored `scrolloff` if `centering` is false.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 31a2f582..26389026 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1667,12 +1667,7 @@ fn search_impl(
};
doc.set_selection(view.id, selection);
- // TODO: is_cursor_in_view does the same calculation as ensure_cursor_in_view
- if view.is_cursor_in_view(doc, 0) {
- view.ensure_cursor_in_view(doc, scrolloff);
- } else {
- align_view(doc, view, Align::Center)
- }
+ view.ensure_cursor_in_view_center(doc, scrolloff);
};
}
@@ -2434,8 +2429,10 @@ fn jumplist_picker(cx: &mut Context) {
(),
|cx, meta, action| {
cx.editor.switch(meta.id, action);
+ let config = cx.editor.config();
let (view, doc) = current!(cx.editor);
doc.set_selection(view.id, meta.selection.clone());
+ view.ensure_cursor_in_view_center(doc, config.scrolloff);
},
|editor, meta| {
let doc = &editor.documents.get(&meta.id)?;
@@ -4205,6 +4202,7 @@ fn match_brackets(cx: &mut Context) {
fn jump_forward(cx: &mut Context) {
let count = cx.count();
+ let config = cx.editor.config();
let view = view_mut!(cx.editor);
let doc_id = view.doc;
@@ -4218,12 +4216,13 @@ fn jump_forward(cx: &mut Context) {
}
doc.set_selection(view.id, selection);
- align_view(doc, view, Align::Center);
+ view.ensure_cursor_in_view_center(doc, config.scrolloff);
};
}
fn jump_backward(cx: &mut Context) {
let count = cx.count();
+ let config = cx.editor.config();
let (view, doc) = current!(cx.editor);
let doc_id = doc.id();
@@ -4237,7 +4236,7 @@ fn jump_backward(cx: &mut Context) {
}
doc.set_selection(view.id, selection);
- align_view(doc, view, Align::Center);
+ view.ensure_cursor_in_view_center(doc, config.scrolloff);
};
}