Godot-proposals: Allow text multi-selection in the code editor

Created on 20 Nov 2019  路  11Comments  路  Source: godotengine/godot-proposals

Describe the project you are working on:
A code where I have to copy-paste code that has only one small variation in the variable and node name.

Describe the problem or limitation you are having in your project:
Having to change every variable name one by one is really cumbersome, the workflow would get way faster if we could multi-select a selected part of the string, exactly like CTRL-D in Sublime Text. So for example if I select 'Name' in $nodeName, I can select all next (or previous) duplicates that also have 'Name' in it. And then modify them all at once.

Describe how this feature / enhancement will help you overcome this problem or limitation:
Well it's a feature that's in all IDEs and we programmers got used to it, I'm quite surprised it's not available in Godot. Maybe I just missed it, but I've looked and asked and nothing was found, I also tried shortcuts like ctrl-D, alt-ctrl-D and stuff. So this enhancement is clearly about speeding the programming workflow as we often have to change a few similar strings.

By the way it's not really replaceable by Search-And-Replace since this one applies the change on all results in the document. Multi-Select allows to change only a few strings and not all of them, very useful for replacing variable or node names only in a function for example.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
Screen Shot 2019-11-20 at 16 07 33

Describe implementation detail for your proposal (in code), if possible:
Um not experienced enough for this, but I guess it's a Regex trick where pressing the shortcut will search for the next matching string and so on ?

If this enhancement will not be used often, can it be worked around with a few lines of script?:
It's not really a function used within the dev's code, but an editor tool for programmers to code faster. I think it will be used very often, like moving a line with alt-up and such.

Is there a reason why this should be core and not an add-on in the asset library?:
All programmers are lazy by nature, so are game'devs ^^ So we need it shipped with the code editor !

editor

Most helpful comment

You can keep this one open :)

All 11 comments

I'd really like to have this too, but implementing it sounds pretty difficult :slightly_frowning_face:

Oh ? I thought it wasn't very hard since I guess how the regex would do the work, but I'm not a C++ programmer so I can't know. That's too bad...

@rezgi The main difficulty is handling multiple cursor movement, editing and selection. We don't need regular expressions for what we're doing here.

By the way it's not really replaceable by Search-And-Replace since this one applies the change on all results in the document. Multi-Select allows to change only a few strings and not all of them, very useful for replacing variable or node names only in a function for example.

This can be achieved by enabling Selection Only in the search and replace dialog:

image

Ok I see, indeed it seems difficult. Can you tell me what Selection Only does ? I've tried it and it gives me the same result than a classic search.

Nevermind I understood, it allows to use the arrows to change only what we select :) That's good enough, but I'll consider using an external editor, that adds the advantage of having another window for the code only, before 4.0 brings this feature ;) Thank you very much, should I close the issue ?

With the proper multi-select implementation, you can place cursors in arbitrary locations, that's not possible with search-replace (example below is from vscode, in addition to already mentioned Ctrl+[Alt]+D shortcuts, cursors can be placed by Alt+Click at any number of points and Alt+Shift+Drag can be used to select vertical blocks of text):

optimized

yeah that's a very powerful tool, I use it for many flavors of text multi-editing like the one you mentionned. Guess it's about how much of work it represents to have a multi-cursor in the editor.

Yeah this will be implemented when multi-caret support is added, see godotengine/godot/issues/4884.

No promises as to when, but I'm hoping at the very least to adjust the TextEdit API in 4.0 in preparation for this.

Well fingers crossed ! So, is this issue a duplicate that needs to be closed or should I leave it to complement #4884 ?

You can keep this one open :)

I would separate multiple cursors and multiple selections.
Personally, I do not see a special need to have multiple cursors, but the ability to select several sections of code (for example, several methods) in order to copy them to another file, instead of copying method by method, I think is a very convenient feature.

Was this page helpful?
0 / 5 - 0 ratings