-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Fix indentation in script templates #78675
Conversation
If possible, you could add some unit tests. |
I'm not sure that's possible this is specific to the editor interface AFIK it's just not possible to do unit testing on the editor UI and stuff, and it wouldn't be easy to even do so as it is an internal function like this, I don't think there's any unit tests for any Editor components, but I might be wrong |
Purely theoretical: Copy test-template to Project/script_templates/Node/. |
You can't do that from CLI, this is specific to the editor UI, the |
6d6bcce
to
e5732b8
Compare
} | ||
script_template.content += line.replace("\t", "_TS_") + "\n"; | ||
script_template.content += line.substr(i) + "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To deal with empty lines or lines that are just whitespace, this matches the pre-first non-whitespace character behavior of the old code, and also matches generally the behavior of converting indentation on save
Could simplify it and merge all spaces and combine them at the end but I think this is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested this but it looks good to me.
if (line.begins_with("space-indent")) { | ||
String indent_value = line.substr(17, -1).strip_edges(); | ||
if (line.begins_with("space-indent:")) { | ||
String indent_value = line.substr(13).strip_edges(); | ||
if (indent_value.is_valid_int()) { | ||
int indent_size = indent_value.to_int(); | ||
if (indent_size >= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (indent_size >= 0) { | |
if (indent_size > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to change the original support for not converting spaces to indentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this, just suggested as it looks like a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is a mistake it should have an error, but I think it's intentional to simply prevent spaces to be used as indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, the option is not available for tabs. I don't think this is an intentional feature, but I'm not asking you to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, will see, thank you for your feedback!
There was a check for the value non-zero in the original code so it was at least not a simple error of taking >=
over >
in the original code.
Will add an error though as it doesn't error out if you have a negative number
e5732b8
to
3935346
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me.
Thanks! |
Thank you! |
Cherry-picked for 4.1.3. |
Uses a variation on the code from
CodeEdit
, works well in my testing, also fixes the parsing ofmeta-space-indent
which was not updated and used the wrong spacing and error messageWould be useful to be able to unify the code but the code for
CodeEdit
turns one type of indentation into another instead of turning two types of indentation into one special sequence