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

Multi Caret Selection Mode #279

Closed
oxysoft opened this issue Apr 3, 2019 · 5 comments
Closed

Multi Caret Selection Mode #279

oxysoft opened this issue Apr 3, 2019 · 5 comments

Comments

@oxysoft
Copy link

oxysoft commented Apr 3, 2019

Just an idea which I thought could work perfectly with AceJump's other existing features, and fits the name "AceJump" quite well I think. There is a shortcut I use religiously which is "Add Selection for Next Occurence". AceJump could have a mode which enters by pressing a different shortcut, and let's you navigate occurrences of the current word under the caret using:

  • Arrow keys to move between search results, starting with the word under the caret.
  • SPACE/ENTER to toggle the selection on the active word.
  • ESCAPE/ENTER to leave the mode.

When leaving the multi-caret editing (e.g. when pressing escape) the editor must return to a default caret. Usually this is the beginning location before leaving single-caret editing. For this mode, it could be done in many ways:

  • HOME to leave the mode and set the active caret at the first location. (vertically)
  • END same as above but last location.
  • ESCAPE/ENTER can be set by the user in the settings, defaults to start location.
  • ACEJUMP to decide!?

I think this would be an insane editing tool because you could selectively discard occurrences (leave holes) which is a very common jerk in the workflow.

@breandan
Copy link
Collaborator

breandan commented Apr 3, 2019

Bonjour @oxysoft, merci pour la suggestion. I believe @saroff had the idea first, is this the same as #221?

@oxysoft
Copy link
Author

oxysoft commented Apr 3, 2019

That issue does aim to achieve the same goal but I think the implementation is different from mine.

If I understand right, the main difference is suggesting we type the tag for each match. I think this won't scale well to many real life examples. The goal for the mode I described here is to be almost an extension to the Add Selection for Next Occurrence action of the IDE. The shortcut used to enter the mode should probably also reused as a selection toggle key within the mode too, that way a user could go as far as replacing the default shortcut for Add Selection for Next Occurrence with AceJump's, and the only difference would be that they'd have to press the toggle key again for the initial selection* and ESCAPE/ENTER to leave the mode and begin the batch editing. If you enter the mode with text already highlighted in the editor, then it would search for it instead of the word under the caret, just like the default behaviour of the action. It would probably be best if the toggle action also advanced the cursor to the next match, but do offer an alternate toggle action too which doesn't advance and can be mapped to preference.

* The reason it could be good to not immediately toggle the first match is that this mode could also double as a navigation tool! When leaving the mode with 0 selections toggled, the caret should remain at the final location, that way we can navigate the caret between matches. Coupled with a key to cycle through the last few searches (while already in the mode) it could potentially hold a powerful new way to navigate code. Gotta try it to know for sure though.

Additional Notes:

  • It would be totally possible to also add a rapid-fire mode which shows tags next to each match and lets you type them in just like Feature request: AceJump + multiple caret #221 is proposing. The rapid-fire mode could be entered immediately with a shortcut or toggled on and off by pressing a certain key while in Multi Caret Selection Mode. (Multi Caret Selection Mode #279)
  • It would be possible to enter the mode from within AceJump's basic jump mode by converting the typed text/tags to matches, using a shortcut! This creates an additional layer of power because you don't have to have your caret positioned already.

It is reinventing the wheel a bit in a way since this is basically the CTRL-F bar of the editor, but then again AceJump by default is also reinventing the mouse too. I think dedicated modes like these which integrate well into the keyboard to create a seamless workflow with low hand motion are the reason Vim and other similar editors flourish even today. The advantage of doing it this way is that we don't have to bind a bunch of crazy shortcuts to use convoluted actions from the search bar, you simply shift into a cool new contextual keyboard mode that has its own properties and easy shortcuts. Our hand is almost always hovering above the arrows, so the mode can be entered with a shortcut of the left-hand and then we can navigate straight away with UP and DOWN for example. Plus we get to reuse AceJump's efficient tagging system for all kinds of purposes.

@oxysoft
Copy link
Author

oxysoft commented Apr 5, 2019

Hi, I have submitted to YouTrack a draft for a flexible and specialized code navigator which Jetbrains could add to their base platform https://youtrack.jetbrains.com/issue/RIDER-26434. This navigator at its core would allow navigation of a list of stops. It could also support a selection mode exactly as described in this AceJump issue which is why I'm linking this here as well.

The default behaviour of picking the word under the caret explained here doesn't have to be an AceJump feature, it can simply be a base functionality of the IDE which uses the navigator. However, further features could be added such as typing a random word in the file (using AceJump's tagging system) and converting the matches to navigator stops. AceJump would simply have to use the navigator api to start it using its own custom list of stops to navigate through. AceJump could also offer a shortcut to convert navigator stops to tags and back and forth (acts as a toggle), that way it would result in a seamless experience between the navigator and AceJump.

This comment will certainly make more sense after reading the YouTrack article above but I should warn you, it's also really really long. I believe only Resharper and Rider have Structural Navigation so far (C# only) so you may have to look it up to understand what it looks like exactly, since this also a suggested precursor to Structural Navigation.

@breandan
Copy link
Collaborator

breandan commented Apr 7, 2019

Hi Nicolas, thank you for the detailed feature proposal. While I cannot promise to implement this, I can see the value of your proposal and AceJump welcomes contributions. Please let me know if you would be interested in working on this feature. If so, MultiCaretCodeInsightAction is a good place to get started.

@breandan
Copy link
Collaborator

breandan commented Apr 4, 2021

I noticed that IdeaVim's multi-caret selection mode has recently improved. As discussed here, I am a little hesitant to add features that overlap with IdeaVim functionality, although it may be possible to offer a smoother multi-caret integration. In any case, let's merge this discussion with #350. Thank you for the suggestion!

@breandan breandan closed this as completed Apr 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants