-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add an option to trim trailing whitespace on all lines except the current line when saving a script #3229
Comments
On a related note, "Trim Trailing Whitespace On Save" and "Autosave Interval Secs" are unusable when both enabled. Autosave will trigger every few seconds which will strip away spaces and tabs in the middle of typing a line. I threw together some code today which stops the whitespace on the current line from being stripped. I also added whitespace stripping to the GDScript save function so that the file on disk will be stripped. That way trailing whitespace won't be left over for Git to complain about. This is my first attempt at developing on the Godot engine so feedback is welcomed and appreciated. |
Would there ever be a case for not having this set to |
If you want to commit to version control just after closing the editor while on a line with trailing whitespace, yes. DragonAxe's solution of only keeping whitespace in the internal editor is interesting (i.e. only in RAM, not on disk). It would allow for keeping whitespace on the current line in the editor, but not keep it in the saved copy. That said, I haven't seen something like this being used in production in any other code editor or IDE I know of. There may be unforeseen consequences of dissociating the saved copy from the in-memory version in the editor. I still feel like it's worth a try nonetheless 🙂 |
As it seems the q&d solution ´if ((line.ends_with(" ") || line.ends_with("\t")) && text_editor->get_caret_line() != i) {´ is off the table, may I suggest to only protect the text left of the cursor? What's to the right of it and after any text can safely be considered "trailing". About desyncing the memory copy and the file: Yes, this is a potential source for follow-up issues. Were I to design this, I would add a "current line edit buffer" that always sits between the user input and the back buffer. It would work as a write-through buffer for all normal text input and be the source for the rendered text, but would not be updated by the whitespace stripping on autosave. As it updates the back buffer on every user input, it can be safely discarded when the editor is closed even if it is desynced---the only possible desync is a whitespace mismatch. |
Describe the project you are working on
The Godot editor 🙂
Describe the problem or limitation you are having in your project
The On Save > Trim Trailing Whitespace editor setting will trim trailing whitespace on all lines in the script editor when saving a script. This also applies to the current line, which means your cursor will likely more unexpectedly if you move to a new indented line then save the script.
When coming from other IDEs that support this, it feels like a small but noticeable UX papercut when scripting in Godot.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add an option to trim trailing whitespace on all lines except the current line when saving a script.
For instance, JetBrains IDEs use this option by default.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Change this setting from a boolean to an enum with the following options:
This option should not affect manual whitespace trimming using the appropriate menu option.
If this enhancement will not be used often, can it be worked around with a few lines of script?
No, as whitespace trimming is handled by CodeEdit itself.
Is there a reason why this should be core and not an add-on in the asset library?
See above.
Footnotes
I think we could default to All Lines Except Current in the future, but this is better discussed in a separate proposal once this feature is implemented. ↩
The text was updated successfully, but these errors were encountered: