Fixed double click word highlight not accounting for numbers/single letters

This commit is contained in:
bigguy345 committed 2025-12-18 10:48:34 +02:00
1 parent 1ab26a9e84
commit 19e5213f3c
2 files changed
+4 -6

No files matched your search

@@ -5,8 +5,8 @@ import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ChatAllowedCharacters;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.client.ClientProxy;
import noppes.npcs.client.gui.util.script.JavaTextContainer;
import noppes.npcs.client.gui.util.script.JavaTextContainer.LineData;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
@@ -15,9 +15,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import noppes.npcs.client.gui.util.script.JavaTextContainer.LineData;
import org.lwjgl.opengl.GL11;
import static net.minecraft.client.gui.GuiScreen.isCtrlKeyDown;
public class GuiScriptTextArea extends GuiNpcTextField {
@@ -1471,7 +1468,7 @@ public class GuiScriptTextArea extends GuiNpcTextField {
this.doubleClicked = true;
Matcher m = this.container.regexWord.matcher(this.text);
while (m.find()) {
if (this.cursorPosition > m.start() && this.cursorPosition < m.end()) {
if (this.cursorPosition >= m.start() && this.cursorPosition <= m.end()) {
this.startSelection = m.start();
this.endSelection = m.end();
break;
@@ -15,7 +15,8 @@ public class TextContainer {
public final Pattern regexString = Pattern.compile("([\"'])(?:(?=(\\\\?))\\2.)*?\\1", Pattern.MULTILINE);
public final Pattern regexFunction = Pattern.compile("\\b(if|else|switch|with|for|while|in|var|const|let|throw|then|function|continue|break|foreach|return|try|catch|finally|do|this|typeof|instanceof|new)(?=[^\\w])");
public final Pattern regexType = Pattern.compile("\\b(Array|Date|eval|hasOwnProperty|Infinity|isFinite|isNaN|isPrototypeOf|Math|NaN|Number|Object|prototype|String|toString|undefined|valueOf|parseInt|parseFloat|print)(?=[^\\w])");
public final Pattern regexWord = Pattern.compile("[\\p{L}-]+|\\n|$");
// Include letters, numbers and underscore so single chars like "x" and numeric tokens match
public final Pattern regexWord = Pattern.compile("[\\p{L}\\p{N}_-]+|\\n|$");
public final Pattern regexNumber = Pattern.compile("\\b-?(?:0[xX][\\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?(?:[fFbBdDlLsS])?|NaN|null|Infinity|unidentified|true|false)\\b");
public final Pattern regexComment = Pattern.compile("\\/\\*[\\s\\S]*?(?:\\*\\/|$)|\\/\\/.*|#.*");