-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Jump mode #3791
Jump mode #3791
Conversation
I ran the video at half the speed and still didn't get what keys are being pressed :) |
Thanks for the effort. |
Fortunately, that's already how the code in this PR is laid out; finding the locations to jump to and labelling and going through with the jumping are separate, although they exist within the same function right now. |
Each jump in the video is 4 to 5 keystrokes:
Ah right I see what you mean. Allowing the jump location calculation mechanism to be configured brings up the question of what exactly the configuration options should be, so I'll definitely need some input on that front. |
My favorite implementation is in Amp.rs: https://amp.rs/docs/usage/#jump-mode |
It looks like Amp exclusively uses 2-character jump labels; I have this PR set up to allow jump labels to be as long as is necessary, although that length would usually not exceed 2 and in practicality never exceed 3. The important thing though is that different jump labels have different lengths; farther jump locations use longer labels. I'm wondering if we should provide two jump mode keybinds: one to jump to words for faster jumping, and one that takes an extra search keypress for precision jumping. |
Unfortunately, my knowledge of the helix codebase (and Rust, as well) is still insufficient to work on this, so I can only suggest. |
Well, one is already implemented in this PR, and the other I actually implemented in the original jump mode PR (#1162), I'd just have to combine them. Although first, I'd like to get a maintainer's feedback on this configurability / two jump mode keybinds aspect. |
Maybe we could have 3 separate commands:
The latter could be the one that is bound in the default key bindings. |
How about two commands:
I don't see a reason to separate "tree-sitter" from "tree-sitter with fallback". |
Also, with tree-sitter or word-wise jumping, should we select the destination syntax node/word? |
Yeah, two commands sounds good to me too. Personally I think selecting the whole word/node makes the most sense. |
I've pushed an initial implementation of word-wise jumping (no tree-sitter support yet) that selects the word that was jumped to. I've additionally made the character search jump (now bound to |
Should a new theme key be added for the jump labels? What should it be called? |
I haven't given this a proper look yet but I think it could be cleaner to create and merge jump label highlights in the same way we currently create & merge diagnostics and cursors: helix/helix-term/src/ui/editor.rs Lines 120 to 135 in 0361217
helix/helix-term/src/ui/editor.rs Lines 262 to 302 in 0361217
I do think this should be themable 👍. I don't have strong opinions on the theme key name though. |
Great that you're working on this further! Like one of the commenters, I'm open to the most user-efficient implementation getting preferential treatment, even if it differs from what I'm used to. Personally my sense was that populating the screen with keys close to j/k has the lowest mental and mechanical overhead, compared to e.g. first typing the specific letter one aims for. But I didn't test the alternatives for a sufficiently long time. |
About the tree-sitter integration idea… with all the syntax nodes that can be and usually are present, I'm not sure how to approach choosing jump locations, or if we should even be pursuing integrating tree-sitter with jump mode at all. I think I need commentary from someone who's more familiar with working with tree-sitter. |
A tree-sitter version of this would be interesting. There would need to be autocomplete for the node names but even then it would be potentially confusing because each tree-sitter grammar uses its own node names which are almost never documented and sometimes have odd naming conventions. It would be a fun experiment but I would definitely leave it out of this PR EDIT: I don't think it would be really possible to do it with jump labels because they would be overlapping most of the time. So instead I was thinking of something like search or select, which is different from this feature |
Alright, then in that case, I think all that's really left for this PR is adding theming support and getting #417 merged. I'm excited! 🎉 |
Currently supports putting annotations at EOL and overlaying.
Interesting, didn't thought about that. I just tried it out, yup not good experience. I picked the following paragraphs from the analects (original text, non-translated, non-explained https://lunyu.5000yan.com/). With With Can double check where the jumps are located against the first screen then you probably noticed some issues. Although not all users may use CJK characters, but I think even emojis might be affected. |
It seems like the jump label location calculation is malfunctioning for multibyte characters. I'll see what I can do. |
I also think there's a bug where the jump labels will stop being generated if a line that extends off screen is reached, because it thinks offscreen means off the bottom/top of the screen. |
I just did some testing and it seems like the cursor actually jumps to the correct locations, but the labels are in the wrong locations. In my code, I calculate the text annotation positions by using |
Oh, it turns out I just needed to use |
Given the plans to change the virtual text strategy (#417 (comment)) will it be a big lift to rework this PR? I'd really love this functionality 😀 |
Well it would depend on how different the interface to the virtual text functionality ends up being. |
I've tried (way too) many jump plugins in various editors, so far the best logic I've found is from https://github.com/msafi/xvsc/tree/master/findJump. The idea is to combine "type word to search" and "type trigger letter to jump". I think the algorithm is roughly like this:
This achieves the following:
|
I thought like this too until I tried https://amp.rs/ |
I did try amp roughly when it was released. I find findJump’s approach better:
|
I agree with @matklad. |
Not quite sure if i follow this findJump/AceJump approach. Its always a little hard to figure out short gif/videos without trying it out yourself. So if i have a text and started the "jump mode" and typed the first chars to where i want to jump like
the text parts that would match my |
And that is the problem.
While in amp.rs approach you leave out the first exercise entirely. |
This PR already contains two different jump mode behaviours: One takes a search character first as described in the original PR comment (bound to |
Hi, I found that the jump to word behaviour will hang if I press it in the middle of the file instead of the start of the file. Here is a file that I try on. It is just a single cpp file. And it will include "\t" as jump point as well. |
Replaced by #5340 |
Supersedes #1162.
Relevant: #274, #510.
This PR depends on virtual text (#417); my commits are currently based on top of that PR. As a result, note that there's a fair chance your config won't work if you check out this branch to test, since the virtual text PR was last rebased several months ago.
As of now, the implementation of this PR takes one keypress after the command is invoked, and then annotates all instances of that key that are on screen and after the cursor with key sequences that can then be typed to jump to that location.
However, I am considering the idea of instead annotating jumps to tree-sitter syntax nodes immediately when the command is invoked, saving a keypress at the cost of some jump precision. What are you all's thoughts on that?
To do:
jump-mode.mp4