aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorwoojiq2023-08-08 13:17:29 +0000
committerGitHub2023-08-08 13:17:29 +0000
commitaa4d84a0b30fbe93882508c6d9dc8ca4c95341d0 (patch)
treece3615ac864edb7b1cf124c744e09d197ff81075 /helix-term/src/commands.rs
parentc1c71bb90edf8fe43584bb103e72bd0e81d36100 (diff)
Align view for background buffer opened with `alt-ret` (#7691)
* fix(picker): `alt-ret' changes cursor pos of current file, not new one Closes #7673 * fix other pickers * symbol pickers * diagnostick pickers This is done using the already patched `jump_to_location` method. * fix global and jumplist pickers * use `view` as old_id; make `align_view` method of `Action` * test(picker): basic <alt-ret> functionality * fix: picker integrational test * fix nit Co-authored-by: Michael Davis <mcarsondavis@gmail.com> --------- Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index e0622559..8be0f83a 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2199,8 +2199,8 @@ fn global_search(cx: &mut Context) {
all_matches,
current_path,
move |cx, FileResult { path, line_num }, action| {
- match cx.editor.open(path, action) {
- Ok(_) => {}
+ let doc = match cx.editor.open(path, action) {
+ Ok(id) => doc_mut!(cx.editor, &id),
Err(e) => {
cx.editor.set_error(format!(
"Failed to open file '{}': {}",
@@ -2209,10 +2209,9 @@ fn global_search(cx: &mut Context) {
));
return;
}
- }
-
+ };
let line_num = *line_num;
- let (view, doc) = current!(cx.editor);
+ let view = view_mut!(cx.editor);
let text = doc.text();
if line_num >= text.len_lines() {
cx.editor.set_error("The line you jumped to does not exist anymore because the file has changed.");
@@ -2222,7 +2221,9 @@ fn global_search(cx: &mut Context) {
let end = text.line_to_char((line_num + 1).min(text.len_lines()));
doc.set_selection(view.id, Selection::single(start, end));
- align_view(doc, view, Align::Center);
+ if action.align_view(view, doc.id()){
+ align_view(doc, view, Align::Center);
+ }
}).with_preview(|_editor, FileResult { path, line_num }| {
Some((path.clone().into(), Some((*line_num, *line_num))))
});
@@ -2742,9 +2743,11 @@ 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);
+ let (view, doc) = (view_mut!(cx.editor), doc_mut!(cx.editor, &meta.id));
doc.set_selection(view.id, meta.selection.clone());
- view.ensure_cursor_in_view_center(doc, config.scrolloff);
+ if action.align_view(view, doc.id()) {
+ view.ensure_cursor_in_view_center(doc, config.scrolloff);
+ }
},
)
.with_preview(|editor, meta| {