The following code is a quick example to demonstrate a simple working repro. Notice that there is no indentation on line 3.
If we paste anything in line 4, it will automatically lose its indentation to align with line 3 rather than respecting the coding scope line 4 should be in.
function testFunc()
local a = 2
if a > 5 then
-- Do something
end
end
Expected Behavior
When pasting code into a specific line, I expect the indentation to be preserved in the coding scope it resides in.
Here is a clip of the proper behavior in Sublime Text
Actual Behavior
When pasting code, the indentations get removed and I am forced to manually re-indent the line to where it was before.
This happens when the white space indentation of the line above the code is not indented. It is very tedious to correct for this issue and we shouldn’t have to be doing it.
Workaround
What happens is now we need to enforce consistent white space indentations in the empty lines above every line of code in order to avoid this issue. This should not be required and has been a huge time waster when refactoring large amounts of code each day.
Issue Area: Studio Issue Type: Other Impact: Moderate Frequency: Constantly
Setting Auto Indent Rule to “Absolute” will solve this particular issue, but also introduces some edge cases that is not necessarily desirable depending on user preference.
I think both “Relative” and “Absolute” settings try too hard to enforce indentations when pasting code. But setting Auto Indent Rule to “Off” would also be very inconvenient when entering down new lines.
It would be convenient if there was another option that does not modify indentations when specifically pasting code while following the “Absolute” ruleset for the most part.
Here is another comparison between Sublime Text to better illustrate how this option should behave:
Actually, disregard this.
After reading @idevride’s comment, seems like turning off “Format on Paste” solves this exact behavior.
In conclusion, I needed set the following studio settings for the desired indentation behavior: Auto Indent Rule → Absolute Format On Paste → False
My suggestion would be that these should be the default studio settings.
Or better yet, it would be useful if there was some article explaining the Script Editor studio settings.
I don’t think a developer unfamiliar with Roblox Studio would know exactly which settings to look for when they are transitioning from outside IDE/Text editors like VSCode or SublimeText when running into this.
Totally agree about the documentation; Not sure yet what we can do about the defaults, it’s often hard to change defaults that have been around for a while but it is a reasonable suggestion to follow industry standard (Sublime, VSCode etc).
If people feel strongly about this default either way, please chime in here! Thank you!