mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 20:07:32 +00:00
oops forgor
This commit is contained in:
1 parent
117f85096f
commit
d1db2067f8
1 file changed
+70
+70
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.util.script.autocomplete;
|
||||
import noppes.npcs.client.gui.util.script.JavaTextContainer.LineData;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.ScriptDocument;
|
||||
import noppes.npcs.client.gui.util.script.interpreter.ScriptTextContainer;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -177,6 +178,50 @@ public class AutocompleteManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when cursor position changes (e.g., arrow keys).
|
||||
* Updates the autocomplete prefix based on the new cursor position.
|
||||
*/
|
||||
public void onCursorMove(String text, int cursorPosition) {
|
||||
if (!active)
|
||||
return;
|
||||
|
||||
// Check if we're still in a valid identifier position
|
||||
if (cursorPosition < 0 || cursorPosition > text.length()) {
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the word boundaries at the current position
|
||||
int wordStart = cursorPosition;
|
||||
while (wordStart > 0 && Character.isJavaIdentifierPart(text.charAt(wordStart - 1))) {
|
||||
wordStart--;
|
||||
}
|
||||
|
||||
int wordEnd = cursorPosition;
|
||||
while (wordEnd < text.length() && Character.isJavaIdentifierPart(text.charAt(wordEnd))) {
|
||||
wordEnd++;
|
||||
}
|
||||
|
||||
// Check if we moved out of the current word
|
||||
if (cursorPosition < prefixStartPosition || cursorPosition > prefixStartPosition + currentPrefix.length()) {
|
||||
// Check if we're in a different word that we can autocomplete
|
||||
boolean isMemberAccess = wordStart > 0 && text.charAt(wordStart - 1) == '.';
|
||||
|
||||
if (isMemberAccess || wordStart < cursorPosition) {
|
||||
// Update to the new word
|
||||
prefixStartPosition = wordStart;
|
||||
updatePrefix(text, cursorPosition);
|
||||
} else {
|
||||
// Moved to empty space or invalid position
|
||||
dismiss();
|
||||
}
|
||||
} else {
|
||||
// Still in same word, just update the prefix
|
||||
updatePrefix(text, cursorPosition);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly trigger autocomplete (Ctrl+Space).
|
||||
@@ -373,6 +418,26 @@ public class AutocompleteManager {
|
||||
if (!active) return false;
|
||||
return menu.mouseScrolled(mouseX, mouseY, delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse release.
|
||||
* @return true if the release was consumed
|
||||
*/
|
||||
public boolean mouseReleased(int mouseX, int mouseY, int button) {
|
||||
if (!active)
|
||||
return false;
|
||||
return menu.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse drag.
|
||||
* @return true if the drag was consumed
|
||||
*/
|
||||
public boolean mouseDragged(int mouseX, int mouseY) {
|
||||
if (!active)
|
||||
return false;
|
||||
return menu.mouseDragged(mouseX, mouseY);
|
||||
}
|
||||
|
||||
// ==================== ITEM SELECTION ====================
|
||||
|
||||
@@ -416,6 +481,11 @@ public class AutocompleteManager {
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
if (active) {
|
||||
menu.draw(mouseX, mouseY);
|
||||
|
||||
if (Mouse.isButtonDown(0))
|
||||
mouseDragged(mouseX, mouseY);
|
||||
else
|
||||
mouseReleased(mouseX, mouseY, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user