Add Selection and Caret for Next Occurrence of Selection#67644
Conversation
9608cd1 to
d29ccba
Compare
bruvzg
left a comment
There was a problem hiding this comment.
Ctrl/Command + G will conflict with macOS action script_text_editor/find_next Meta + G (Meta and Command are the same key).
Any suggestion @bruvzg ? I was thinking |
I'm not sure. Alt + G is used to input |
d29ccba to
0c1a348
Compare
dae3e41 to
caece58
Compare
|
If this is a keyboard shortcut that exists in JetBrains or VS Code we could use their combination for mac? Not sure where I can find that info myself at the moment 😅 |
@coppolaemilio The names in both VS Code and JetBrains: |
|
VSCode on macOS use |
Paulb23
left a comment
There was a problem hiding this comment.
I would be tempted to swap the ui_text_select_word_under_caret and ui_text_add_selection_for_next_occurrence shortcuts to better align with other editors.
In VSCode, rather then only using the last caret, seems to check whether all carets have the same word selected before selecting the next occurrence. Though interestingly sublime and Jetbrains do only use the last caret. Not necessary need to change, but probably worth putting in the docs.
Secondly, in both VSCode and sublime, if one or more carets do not have a selection it behaves like ui_text_select_word_under_caret (without deselecting). Jetbrains has the same behaviour but only for the last caret.
@Paulb23 that's a good one. I'll add the |
No strong preference, both are good. Can go with the Jetbrains approach for now as it's simpler. Can always change it later. |
Adds the bind `add_selection_for_next_occurrence` to TextEdit, with CTRL+D as the default shortcut. When the bind is performed, ff a selection is currently active with the last caret in text fields, searches for the next occurrence of the selection, adds a caret and selects the next occurrence. If no selection is currently active with the last caret in text fields, selects the word currently under the caret. The action can be performed sequentially for all occurrences of the selection of the last caret and for all existing carets. The viewport is adjusted to the latest newly added caret. The bind and the behaviour is similar to VS Code's "Add Selection to Next Find Match" and JetBrains' "Add Selection for Next Occurrence". It takes advantage of the multi-caret API. The default shortcut for `select_word_under_caret` has been changed to ALT+G, in order to give priority to CTRL+D for `add_selection_for_next_occurrence` to better align with popular IDEs and editors.
caece58 to
7d15ecc
Compare
@Paulb23 Ok, I just implemented the JetBrains behaviour (and all other changes we talked about). The PR has also been updated with an additional example video (regarding the JetBrains select word under caret behavior) and new instructions. |
clayjohn
left a comment
There was a problem hiding this comment.
Looks good to me and Paulb23 is the maintainer here, so let's go ahead and merge
|
Thanks! |
Adds the bind `ui_text_remove_secondary_carets` to TextEdit, with ESC as the default shortcut. When the bind is performed, if the TextEdit has multiple carets, `remove_secondary_carets` is called and secondary carets are removed. This is useful when multiple selects are performed with `add_select_for_next_occurrence` godotengine#67644 or when multiple multiple carets are manually added, then it's possible to go back to a single caret with a shortcut. Closes godotengine#67991
Adds the bind `ui_text_remove_secondary_carets` to TextEdit, with ESC as the default shortcut. When the bind is performed, if the TextEdit has multiple carets, `remove_secondary_carets` is called and secondary carets are removed. This is useful when multiple selects are performed with `add_select_for_next_occurrence` godotengine#67644 or when multiple multiple carets are manually added, then it's possible to go back to a single caret with a shortcut. Closes godotengine#67991
You seem to be using Godot 3, and this PR is for Godot 4. |




Adds the bind
add_selection_for_next_occurrenceto TextEdit, withCTRL+Das the default shortcut.When the bind is performed, if a selection is currently active with the last caret in text fields, searches for the next occurrence of the selection, adds a caret and selects the next occurrence.
If no selection is currently active with the last caret in text fields, selects the word currently under the caret.
The action can be performed sequentially for all occurrences of the selection of the last caret and for all existing carets. The viewport is adjusted to the latest newly added caret.
The bind and the behaviour is similar to VS Code's "Add Selection to Next Find Match" and JetBrains' "Add Selection for Next Occurrence". It takes advantage of the multi-caret API.
The default shortcut for
select_word_under_carethas been changed to ALT+G, in order to give priority to CTRL+D foradd_selection_for_next_occurrenceto better align with popular IDEs and editors.Implements and closes godotengine/godot-proposals#5621
Usage
Define an Editor Shortcut for
ui_text_add_selection_for_next_occurrence(default:CTRL+D):Select text and keep pressing the shortcut to select the next occurrences:
multi-selection-godot3.mp4
If no selection is currently active, it selects the word under caret. If a new caret is manually added with a different selection (or no selection), the selection of the new caret is taken into consideration (like VS Code and JetBrains):
godot-multi-selection-vscode-like.mp4
It also supports manually adding a new caret to skip some occurrences. For example, in this instance I skipped some of the middle
@exportoccurrences:multi-selection-manually-add-cursor.mp4
Known Limitation
Currently, the selection cannot span more than one line/cannot contain line breaks. In the example video below, I tried to select:
But it didn't work because the selection included a new line. Selecting only
move,worked:multi-selection-multi-linesno.mp4