mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 05:19:41 +00:00
Fixed token position calculation under mouse being inconsistent under single character tokens "y"
This commit is contained in:
1 parent
e0b4aece90
commit
25800e9c3d
2 files changed
+15
-5
No files matched your search
@@ -14,6 +14,7 @@ import noppes.npcs.client.gui.util.script.JavaTextContainer.LineData;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.ScriptLine;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.ScriptTextContainer;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.Token;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.TokenType;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.hover.HoverState;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.hover.TokenHoverRenderer;
|
||||
import noppes.npcs.client.key.impl.ScriptEditorKeys;
|
||||
@@ -997,7 +998,7 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
|
||||
// Get the token at this position
|
||||
int globalMouseX = getSelectionPos(xMouse,yMouse);
|
||||
Token token = scriptContainer.getInterpreterTokenAt(globalMouseX);
|
||||
Token token = lineData.getTokenAt(globalMouseX, (t) -> t.getType() != TokenType.DEFAULT); // Ignore default tokens i.e. whitespaces
|
||||
if (token == null)
|
||||
return null;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.lwjgl.opengl.GL11;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Represents a single line of source code with its tokens.
|
||||
@@ -70,14 +71,22 @@ public class ScriptLine {
|
||||
}
|
||||
|
||||
public Token getTokenAt(int globalPosition) {
|
||||
for (Token t : tokens) {
|
||||
if (globalPosition >= t.getGlobalStart() && globalPosition <= t.getGlobalEnd()) {
|
||||
for (Token t : tokens)
|
||||
if (globalPosition >= t.getGlobalStart() && globalPosition <= t.getGlobalEnd())
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Token getTokenAt(int globalPosition, Predicate<Token> condition) {
|
||||
for (Token t : tokens)
|
||||
if (globalPosition >= t.getGlobalStart() && globalPosition <= t.getGlobalEnd() && condition.test(t))
|
||||
return t;
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
// ==================== TOKEN MANAGEMENT ====================
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user