godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Improve Godot Text Editor to enable precise navigation using keyboard #9837

Open vgezer opened 3 months ago

vgezer commented 3 months ago

Describe the project you are working on

It is actually not a project, but a generic idea to improve code editor on Godot itself.

Describe the problem or limitation you are having in your project

I like the way of using keyboards on IDEs for almost anything as if I am on a console/terminal.

For example, duplicating lines, deleting a word, deleting from cursor, or deleting until cursor using keyboard increases my productivity speed.

Some IDEs detect the words on variables/functions even there is no space between them:

and this allows easier and faster editing the words partially. Let's see the current situation in Godot:

I have this variable: this_is_my_very_long_variable. I would also like to create this_is_his_very_long_variable as a second variable. What I can currently do in Godot is to copy it or use auto-completion by typing thi. Then moving caret left until I reach my and replacing it with his. Alternatively, I can click with mouse, but it is not practical.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

If we make editor also capitalization or underscore aware, then, if I want to just edit the middle of a long variable, I can just use the Ctrl+Left or Ctrl+Right to jump to the location where I need to modify. In the example above, I can just use Ctrl+Left 4 times.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

In text_edit.cpp,

I modified the _move_caret_right and _move_caret_left functions to consider the option to stop if it detects an underscore, if it is enabled in editor settings.

Here is what it looks like in the editor settings:

image

If this option is enabled (it is disabled by default), copying and pasting the line, then using Ctrl + Left 4 times moves the caret to:

image

If I then keep Shift pressed then use Ctrl+Right, I just mark "my" and easily change to "his".

image

I already have the diff to integrate the underscore version. If it is found to be useful, I can send a pull request for underscore. Then, one can improve it to detect case differences to move caret in these cases as well.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not with scripts, but using Left key multiple times.

Is there a reason why this should be core and not an add-on in the asset library?

This is a generic productivity enhancement, not project specific.

Calinou commented 3 months ago
RedMser commented 3 months ago

I can send a pull request for underscore

You might want to move the editor setting to the "Behavior" category, instead of "Appearance" where it does not really fit.

Other than that, I'm totally in favor of adding an option for this + the linked issue by Calinou.

Calinou commented 3 months ago

Many editors feature a "word separators" setting which is a list of non-whitespace characters that are used as word delimiters. It's usually a string of the form code>`~!@#$%^&amp;*()-=+[{]}\|;:'",.&lt;&gt;/?</code (this is the default in VS Code).

Characters that will be used as word separators when doing word related navigations or operations.

vgezer commented 3 months ago

Here we go: https://github.com/godotengine/godot/pull/92514

kitbdev commented 3 months ago

It would also be possible to add a separate shortcut for word parts like ui_text_caret_word_part_right. VSCode has something similar, with no default binds.

vgezer commented 3 months ago

Many editors feature a "word separators" setting which is a list of non-whitespace characters that are used as word delimiters. It's usually a string of the form `~!@#$%^&*()-=+[{]}|;:'",.<>/? (this is the default in VS Code).

Characters that will be used as word separators when doing word related navigations or operations.

I replaced these characters with ´`~$^=+|<> because even without my commit, the other characters are treated as word delimiters and there is no way to ignore them with my PR.