godotengine / godot-proposals

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

In the code editor, keep right side of cursor after autocompletion #9528

Open EchoingLogos opened 4 months ago

EchoingLogos commented 4 months ago

Describe the project you are working on

Game with GDScript.

Describe the problem or limitation you are having in your project

It's a common occurrence that a user wants to backtrack in a line and add some text. The most common use case is when we access something from a different namespace, but forget to specify the namespace. For example:

image

Here, I have to specify that UNHIT comes from the RhythmNote namespace. As I start typing, the autocompletion suggests what I want:

image

However, once I press TAB, the right side of the cursor is deleted:

image

This behavior is personally highly distracting, and I expect it will also be so for other users as it is the kind of behavior that you can't really expect from an editor until you've been exposed to it previously. The solution of holding down a modifier key to avoid the behavior is hard to come across on one's own, and rather janky.

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

Providing a toggle for users whose focus is easily upset by code editors doing party tricks for the sake of "convenience" while making the more common use cases (from the perspective of said user) terribly inconvenient would greatly improve the comfort of writing code.

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

In the editor settings for the code editor, a toggle is provided to remove this behavior.

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

No.

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

N/A

Calinou commented 4 months ago

I don't see a reason why this behavior would be desirable. And to the extent of my knowledge, Godot is the only code editor that treats auto-completion like this.

Most editors like VS Code actually behave like Godot is currently working:

https://github.com/godotengine/godot-proposals/assets/180032/4dece7de-79ae-43e7-91ce-6c92f1e04ff8

Replacing the end of the word is often (but not always) desired when doing autocompletion, as it can save a lot of time. The autocompletion system doesn't know that you want to replace UNHIT with RythmNote.UNHIT (this is a rather specific scenario when it comes to autocompletion).

This sounds like something that should be addressed by holding down a modifier when you don't want the text until the end of the word to be replaced. In VS Code, holding down Shift when pressing Enter will do that. (This doesn't work when clicking the suggestion with the mouse though.) Ctrl + Enter will ignore the autocompletion prompt and go to the next line.

EchoingLogos commented 4 months ago

I must have changed something in VS code. It doesn't do this for me.

I have to say that this happens to me about once every ten minutes while writing code in the Godot editor, as opposed to the use case that it's meant to help with (which is quickly dealt with with Ctrl + Shift + Right + Backspace/Del, as one would do when auto-correction isn't available).

Keep in mind I've been silently tolerating this ever since it was introduced until I finally snapped today. In any case, I'll edit the proposal to suggest an Editor setting allowing the user to toggle this behavior. The default can stay whatever the standard is.

Calinou commented 4 months ago

In any case, I'll edit the proposal to suggest an Editor setting allowing the user to toggle this behavior. The default can stay whatever the standard is.

I don't think an editor setting is the best way to approach this, as whether you want existing text to be replaced depends on a case-by-case basis. You don't want to have to go through the editor settings every time you want to accept an autocompletion suggestion that requires replacing the text until the end of the word :slightly_smiling_face:

There's also the fact that the editor settings dialog is starting to be pretty complex, with a lot of settings that are barely ever toggled. This adds to the maintenance and QA burden.

kitbdev commented 4 months ago

There are two shortcuts: ui_text_completion_replace (Tab) and ui_text_completion_accept (Enter). The replace one replaces the text while the accept one just inserts it. The shortcuts can be changed in EditorSettings so accept can be set to tab or replace to shift+enter or whatever you want.

EchoingLogos commented 4 months ago

In any case, I'll edit the proposal to suggest an Editor setting allowing the user to toggle this behavior. The default can stay whatever the standard is.

I don't think an editor setting is the best way to approach this, as whether you want existing text to be replaced depends on a case-by-case basis. You don't want to have to go through the editor settings every time you want to accept an autocompletion suggestion that requires replacing the text until the end of the word 🙂

There's also the fact that the editor settings dialog is starting to be pretty complex, with a lot of settings that are barely ever toggled. This adds to the maintenance and QA burden.

It's understandable that one doesn't want to add bloat to the editor settings, as this can discourage users from tweaking the editor to their preferences. Personally, it seems to me that this behavior is so undesirable that 1. one would expect to see it in the settings 2. solutions involving a hotkey to change the behavior dynamically, such as the solution offered by kitbdev, don't help simply getting the behavior off my mind, as there is no situation where I want Tab or Enter to delete the right hand side of the cursor, and the attention load with handling auto-completion is unchanged.

That said, if this proposal fails to garner support, I will acknowledge that this is just a pet peeve of mine and will be happy using VS code or recompiling Godot after taking this behavior out myself.

It's also important to bear in mind that this is the kind of thing that one silently deals with as the vast majority of users won't even notice it. Most of my settings toggles in applications are from behavior that I didn't notice were there until seeing it described in the settings. Anecdotally, while watching a friend coding in Godot I've noticed him struggle with this behavior plenty of times without ever noticing what the problem was.

kitbdev commented 4 months ago

Maybe I wasn't clear, but you can remove the shortcut from ui_text_completion_replace entirely and not need to worry about it. You can configure it like this so that tab and enter both insert text without deleting the text to the right:

image

I think both behaviors have their uses, but maybe we can be more clear about them. I guess we could mention the shortcuts at the bottom of the completion window?

EchoingLogos commented 4 months ago

Maybe I wasn't clear, but you can remove the shortcut from ui_text_completion_replace entirely and not need to worry about it. You can configure it like this so that tab and enter both insert text without deleting the text to the right:

image

I think both behaviors have their uses, but maybe we can be more clear about them. I guess we could mention the shortcuts at the bottom of the completion window?

Sorry if this is obvious, but I'm having trouble finding this menu. I looked at Editor > Editor Settings, Project > Project Settings (Advanced Settings toggled), directly inputted the string into the Project Settings field, and also looked at the Godot editor_settings.xml file, but I didn't find these settings anywhere. (Am using Godot 4.2.1 stable mono)

kitbdev commented 4 months ago

You can find it under Editor > Editor Settings > Shortcuts

image

EchoingLogos commented 4 months ago

Okay, my apologies it was somewhat obvious, had to go to the shortcuts tab in the Editor Settings. I am very glad to see that this was already offered as a setting. I do think we can afford to be more clear about how to find them, since I would initially associate this to a general Editor setting rather than a keyboard shortcut setting, but I have no idea how we could accomplish that without introducing bloat. My toggle proposal is clearly worse functionality-wise than the existing solution of offering shortcut keys for both situations. Would like to hear opinions on how the clarity could be improved as if I hadn't posted about it here I would've had to tolerate it, randomly stumble upon the idea of looking at the Shortcuts tab, or move to a different editor. That said I acknowledge my proposal itself is only indirectly related to such discussion so I would not be surprised if it were closed.