Fixed auto {} brace insertion not respecting existing } that has different indent/whitespaces

This commit is contained in:
bigguy345 committed 2026-02-25 13:04:07 +02:00
1 parent 0c842a22b9
commit 2ca145b264
1 file changed
+11
@@ -1976,6 +1976,17 @@ public class GuiScriptTextArea extends GuiNpcTextField {
String childIndent = indent + " ";
String after = getSelectionAfterText();
// If the next non-whitespace char is '}', don't insert another closer.
int nextNonWs = 0;
while (nextNonWs < after.length() && Character.isWhitespace(after.charAt(nextNonWs))) {
nextNonWs++;
}
if (nextNonWs < after.length() && after.charAt(nextNonWs) == '}') {
addText("\n" + childIndent);
scrollToCursor();
return true;
}
int firstNewline = after.indexOf('\n');
String leadingSegment = firstNewline == -1 ? after : after.substring(0, firstNewline);
if (leadingSegment.trim().length() > 0) {