-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add command to select arbitrary words (similar to goto_label) #10764
base: master
Are you sure you want to change the base?
Conversation
This splits the implemention of jump_to_label into more parts that allow it to be reused in the future for other on-screen pickers. The main way it will be used is by generating some ranges for the labels (see generate_viewport_token_ranges, the function that generates the ranges of visible tokens in the current viewport) and giving those labels to the prompt_for_label function. prompt_for_label calls a callback when a label has been typed. An example of how this could be used in the future is to pick a selection to set as the primary selection.
This command uses the on-screen word picker, the same as goto_word and extend_word, but instead of removing your existing selections, it places a new selection on the picked word. This allows you to select arbitrary words. By default, this is bound to gW (as opposed to goto_word, which is 'gw').
0757fef
to
56daaa5
Compare
What's the intended use-case for this? Since we select words with the jump labels, it's pretty imprecise to add selections this way. I could see it potentially working as expected within prose like markdown documents but for programming languages I would imagine that the jumps aren't precise enough to form useful selections compared to selecting regions and using |
Yeah I would rather see this usecase adressed with marks that allows you to append a selection to the mark. Then you could jump around the screen with commands like |
I'd definitely have thought so too! There's two parts to this that aren't immediately obvious but provide a really nice workflow:
Editing prose is one use for it for sure. Some examples of other workflows I have in mind (there are many more, just what comes to mind immediately):
For prior art, most GUI editors (and as it turns out, some TUI editors too) support doing this by holding a modifier and double clicking. This is functionally a fully text-based equivalent to that, and I think it's also more efficient as a result.
Marks solve a lot of problems and it would be good to have them implemented, but I don't think that they're a particularly elegant solution to selecting arbitrary text. They introduce additional steps and overhead that needs to be considered for what should be a conceptually simple operation. And secondarily, would that be any better than just recording a macro, using Anecdotally, just as a normal user of this editor, when I saw that I hope this hasn't come off as rude or negative! My opinion is that this is a better solution that's also more intuitive, but I understand if you don't feel that way about it. Even if we don't come to a mutual understanding about what makes a simpler / faster / more ergonomic workflow, I think the refactor may still be of value if this type of selection interface is going to be reused in the future by other commands. One that comes to mind would be displaying labels on selections and typing a label to remove the selection, as opposed to the current workflow of cycling through them all until you get to the right one then using As a final note, I trust your judgements on this, if you say marks or macros are the way to go then I've got faith in you as maintainers. I'll keep my fork with this up-to-date though, because this solves a real pain point for me :) |
This PR refactors the
jump_to_label
function to make it reusable for other use cases (now implemented asprompt_for_label
), and implements a new command (add_selection_on_word
) that allows you to add a new selection on any word, instead of replacing the current selection. It addsgW
as a default binding for this.I'm not happy with the names so bikeshedding is welcome.