From 235fd3b3f31a9af8349c6010ee12826815ac9cef Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Mon, 26 Jan 2026 21:52:04 +0200 Subject: [PATCH] Improved comment/string excluded range detection for auto-pair insertion --- .../npcs/client/gui/util/GuiScriptTextArea.java | 2 +- .../gui/util/script/interpreter/ScriptDocument.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java index 977b213b9..3c1f40850 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java @@ -2375,7 +2375,7 @@ public class GuiScriptTextArea extends GuiNpcTextField { // Auto-pair insertion: when opening a quote/brace/bracket is typed, // insert a matching closer and place caret between the pair. // But only if the current position is not excluded (e.g., inside a comment or string) - if (!container.getDocument().isExcluded(cursorPos)) { + if (!container.getDocument().isExcludedInclusive(cursorPos)) { if (c == '"') { setText(before + "\"\"" + after, true); selection.reset(before.length() + 1); diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java index 74f69a175..a571f9576 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/ScriptDocument.java @@ -444,6 +444,17 @@ public class ScriptDocument { public boolean isExcluded(int position) { + for (int[] range : excludedRanges) { + if (position >= range[0] && position < range[1]) { + return true; + } + } + return false; + } + + /** Inclusive version for precision with end offset + Check GuiScriptTextArea#handleCharacterInput */ + public boolean isExcludedInclusive(int position) { for (int[] range : excludedRanges) { if (position >= range[0] && position <= range[1]) { return true; @@ -4739,7 +4750,7 @@ public class ScriptDocument { /** * Mark chained field accesses like: mc.player.world, array.length, this.field, etc. * This handles dot-separated access chains and colors each segment appropriately. - * Does NOT mark method calls (identifiers followed by parentheses) - those are handled by markMethodCalls. + * Does NOT mark method calls (identifiers followed by parentheses) - those are handled by {@link #markMethodCalls}. */ private void markChainedFieldAccesses(List marks) { FieldChainMarker marker = new FieldChainMarker(this, text);