Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align view for background buffer opened with alt-ret #7691

Merged
merged 7 commits into from
Aug 8, 2023

Conversation

woojiq
Copy link
Contributor

@woojiq woojiq commented Jul 20, 2023

Closes #7673

Now if alt-ret is pressed, it opens the selected file and places the cursor on the selected line (if path contained a line number), but in the background (i. e the focused document remains unchanged).

  • All lsp pickers
  • Global search picker
  • Jump list picker

@woojiq

This comment was marked as resolved.

@woojiq woojiq marked this pull request as draft July 21, 2023 12:36
* symbol pickers
* diagnostick pickers

This is done using the already patched `jump_to_location` method.
@woojiq

This comment was marked as resolved.

@woojiq woojiq marked this pull request as ready for review July 22, 2023 10:06
@woojiq woojiq marked this pull request as draft July 22, 2023 10:20
@woojiq woojiq marked this pull request as ready for review July 22, 2023 13:00
@woojiq
Copy link
Contributor Author

woojiq commented Jul 22, 2023

Here we go again. Now all the lsp pickers work correctly because under the hood I added a jump_to_location method instead of their own almost identical implementation. I wanted to add something similar like this method to the non-lsp pickers, but they use slightly different logic, so I just changed the way they get doc_id.

cc @pascalkuthe pr is ready for viewing when you have free time 🤓

helix-view/src/view.rs Outdated Show resolved Hide resolved
helix-view/src/view.rs Outdated Show resolved Hide resolved
Comment on lines -327 to +310
if current_path.as_ref() == Some(url) {
let (view, doc) = current!(cx.editor);
push_jump(view, doc);
} else {
let path = url.to_file_path().unwrap();
cx.editor.open(&path, action).expect("editor.open failed");
}

let (view, doc) = current!(cx.editor);

if let Some(range) = lsp_range_to_range(doc.text(), diag.range, *offset_encoding) {
// we flip the range so that the cursor sits on the start of the symbol
// (for example start of the function).
doc.set_selection(view.id, Selection::single(range.head, range.anchor));
align_view(doc, view, Align::Center);
}
jump_to_location(
cx.editor,
&lsp::Location::new(url.clone(), diag.range),
*offset_encoding,
action,
)
Copy link
Member

@pascalkuthe pascalkuthe Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not quite the same thing. The diagnostic picker only seems to create a jumplist entry if not opening a new file. Admittetly this is a bit strange I would expect the various Lsp pickers to behavhe consistently. Do you know the history here @the-mikedavis?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's just an oversight: pushing a jump all of the time makes sense to me.

@pascalkuthe pascalkuthe added C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 31, 2023
@woojiq
Copy link
Contributor Author

woojiq commented Aug 1, 2023

Added basic integrational test for global search picker. I couldn't test lsp pickers because I need to run an lsp which will be hard to do.

pascalkuthe
pascalkuthe previously approved these changes Aug 1, 2023
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except the change to the diagnostic picker I am not sure about. Let's wait for @the-mikedavis review

@pascalkuthe pascalkuthe added S-waiting-on-review Status: Awaiting review from a maintainer. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 1, 2023
Comment on lines -327 to +310
if current_path.as_ref() == Some(url) {
let (view, doc) = current!(cx.editor);
push_jump(view, doc);
} else {
let path = url.to_file_path().unwrap();
cx.editor.open(&path, action).expect("editor.open failed");
}

let (view, doc) = current!(cx.editor);

if let Some(range) = lsp_range_to_range(doc.text(), diag.range, *offset_encoding) {
// we flip the range so that the cursor sits on the start of the symbol
// (for example start of the function).
doc.set_selection(view.id, Selection::single(range.head, range.anchor));
align_view(doc, view, Align::Center);
}
jump_to_location(
cx.editor,
&lsp::Location::new(url.clone(), diag.range),
*offset_encoding,
action,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's just an oversight: pushing a jump all of the time makes sense to me.

helix-term/tests/test/picker.rs Outdated Show resolved Hide resolved
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
@the-mikedavis the-mikedavis changed the title fix(picker): `alt-ret' changes cursor pos of current file, not new one Align view for background buffer opened with alt-ret Aug 8, 2023
@pascalkuthe pascalkuthe merged commit aa4d84a into helix-editor:master Aug 8, 2023
6 checks passed
@woojiq woojiq deleted the alt-enter-jump-fix branch August 10, 2023 19:50
dgkf pushed a commit to dgkf/helix that referenced this pull request Jan 30, 2024
…7691)

* fix(picker): `alt-ret' changes cursor pos of current file, not new one

Closes helix-editor#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>
mtoohey31 pushed a commit to mtoohey31/helix that referenced this pull request Jun 2, 2024
…7691)

* fix(picker): `alt-ret' changes cursor pos of current file, not new one

Closes helix-editor#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>
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
…7691)

* fix(picker): `alt-ret' changes cursor pos of current file, not new one

Closes helix-editor#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<A-Enter> in the file picker jumps to a line in the current file instead of a new one
3 participants