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

Provide shortcuts/commands for incremental multiselection/multiple carets in text editors #2410

Open
1 of 2 tasks
Adrodoc55 opened this issue Oct 16, 2024 · 7 comments
Open
1 of 2 tasks
Labels
enhancement New feature or request

Comments

@Adrodoc55
Copy link

Adrodoc55 commented Oct 16, 2024

Let's make sure issue is not already fixed in latest builds first.

Suggestion

It seems to me like this issue has been forgotten for a few years even though development was already started: https://bugs.eclipse.org/bugs/show_bug.cgi?id=576377
I am working with eclipse almost every day and for me this is one of the (if not the) most important missing features of the text editor. With "Search All" and the commands "Multi caret down" and "Multi caret up" eclipse is already soo close to supporting this. It would be a blessing if this feature got added and searching though the internet I came across alot of people wishing for this feature.

Since Bugzilla is deprecated and I couldn't find this issue here on GitHub I figured it might be helpful to post this here.

Community

  • I understand suggesting an enhancement doesn't mandate anyone to implement it. Other contributors may consider this suggestion, or not, at their own convenience. The most efficient way to get it fixed is that I implement it myself and contribute it back as a good quality patch to the project.
@Adrodoc55 Adrodoc55 added the enhancement New feature or request label Oct 16, 2024
@mickaelistria
Copy link
Contributor

Feel free to make a suggestion, and even to submit a PR for it.
Note that it must not conflict with an already attributed shortcut (in Preferences > General > Keys). You can try adding your suggestions for the Multi Caret Up/Down commands in that page to ensure they work fine.

@Wittmaxi
Copy link
Contributor

This can be implemented easily with the use of the FindReplaceLogic class. This action should be modeled after the FindNextAction

@mickaelistria
Copy link
Contributor

Ah, it seems like I misunderstood, what you'd like is basically a "Also select next occurrence" ?

@Adrodoc55
Copy link
Author

Adrodoc55 commented Oct 16, 2024

Ah, it seems like I misunderstood, what you'd like is basically a "Also select next occurrence" ?

Yes, after maybe rename and autocomplete, this is probably my most used shortcut in VSCode, because it is soo useful. There it's called editor.action.addSelectionToNextFindMatch and has the shortcut CTRL+D: https://code.visualstudio.com/docs/editor/codebasics#_multiple-selections-multicursor

In VSCode it works like this:

  • If you select a piece of text and activate addSelectionToNextFindMatch then the selected text is entered into the find textbox and using the find-replace options (case-sensitive & whole-word) the next occurence is selected by a new cursor.
  • The regex option is respected, but it doesn't really make a difference, because the selected text is escaped when it is entered into the find textbox.
  • It doesn't matter if the find and replace overlay is currently showing. In both cases the find text is replaced by the selected text and if you later open the find and replace overlay you will see the text you previously selected for addSelectionToNextFindMatch. I don't feel strongly about this part and don't really see much of a benefit in replacing the find text nor in keeping the previous text.
  • If you already have multiple cursors that select equivalent text, then the next occurence is selected by a new cursor starting from the cursor most recently added.
    • Text counts as equivalent if it is identical in case-sensitive mode or if it equal ignoring case in case insensitive mode.
    • When the next occurence is already selected by a cursor, then the viewport moves there but does not add a cursor.
      • In VSCode in this case the most recent curser stays the same so that multiple invocations of the command don't cycle through the occurences. This is useful, because pressing and holding CTRL+D quickly selects all occurences and places you back right where you started.
      • In VSCode this means that if you manually select two occurences (first one later in the text and second one earlier in the text) you get stuck on the first cursor, even if more occurences are present later in the text. I never encountered this until trying out the details to write this description here, so I guess the exact behaviour in this case is not important.
  • If one or more cursors don't have anything selected then addSelectionToNextFindMatch causes those cursors to select their current word. If it was only one cursor it then writes this text into the find textfield and activate both the case-sensitive and whole-word option.
    • The activation of the two options case-sensitive and whole-word stay this way for further invocations of addSelectionToNextFindMatch until you do anything else with any cursor. Unlike the replacement of the find text the changes to case-sensitive and whole-word are not persisted into the find and replace overlay. I think this part is important.
    • In my opinion it would make sense to also update the find text and set the case-sensitive and whole-word options if you have multiple cursors that select identical text du to the invocation of addSelectionToNextFindMatch, but VSCode only does so when it's a single cursor. However this is not important, because this basically never happens in reality.

I hope I covered all edge cases.

@Adrodoc55
Copy link
Author

For reference if anyone finds this helpful here is the implementation of this feature in VSCode: https://github.com/microsoft/vscode/blob/3b82f2a5ec39744f0461824fc3fcde33e3eb6547/src/vs/editor/contrib/multicursor/browser/multicursor.ts#L338

@Adrodoc55
Copy link
Author

I'm wondering: if I were to implement this feature (not sure yet if I'll find the time) I am not sure if I would be able to open a PR on GitHub, because GitHub requires 2FA which I won't activate for various reasons. Would you accept a change that I provide via a fork hosted on another host such as https://codeberg.org?

@mickaelistria
Copy link
Contributor

Would you accept a change that I provide via a fork hosted on another host such as https://codeberg.org/?

I don't think we could do this easily. 2FA is required to prevent from some supply-chain attacks; workflows that bypass 2FA are considered unsafe by the Eclipse Foundation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants