mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 12:15:11 +00:00
Search bar now auto-opens on highlighted word
This commit is contained in:
1 parent
abd639438e
commit
8514b9f980
2 files changed
+20
-16
No files matched your search
@@ -51,6 +51,7 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
|
||||
// ==================== TEXT & CONTAINER ====================
|
||||
public String text = null;
|
||||
public String highlightedWord;
|
||||
private JavaTextContainer container = null;
|
||||
private boolean enableCodeHighlighting = false;
|
||||
|
||||
@@ -89,6 +90,10 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
return GuiScriptTextArea.this.text;
|
||||
}
|
||||
|
||||
public String getHighlightedWord() {
|
||||
return GuiScriptTextArea.this.highlightedWord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String newText) {
|
||||
GuiScriptTextArea.this.setText(newText);
|
||||
@@ -263,8 +268,7 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
drawRect(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0);
|
||||
|
||||
int searchHeight = searchBar.getTotalHeight();
|
||||
y += searchHeight;
|
||||
height -= searchHeight;
|
||||
|
||||
|
||||
// Draw line number gutter background
|
||||
drawRect(x, y, x + LINE_NUMBER_GUTTER_WIDTH, y + height, 0xff000000);
|
||||
@@ -356,12 +360,12 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
}
|
||||
}
|
||||
|
||||
String wordHightLight = null;
|
||||
highlightedWord = null;
|
||||
if (selection.hasSelection()) {
|
||||
Matcher m = container.regexWord.matcher(text);
|
||||
while (m.find()) {
|
||||
if (m.start() == selection.getStartSelection() && m.end() == selection.getEndSelection()) {
|
||||
wordHightLight = text.substring(selection.getStartSelection(), selection.getEndSelection());
|
||||
highlightedWord = text.substring(selection.getStartSelection(), selection.getEndSelection());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,10 +433,10 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
}
|
||||
}
|
||||
//Highlight words
|
||||
if (wordHightLight != null) {
|
||||
if (highlightedWord != null) {
|
||||
Matcher m = container.regexWord.matcher(line);
|
||||
while (m.find()) {
|
||||
if (line.substring(m.start(), m.end()).equals(wordHightLight)) {
|
||||
if (line.substring(m.start(), m.end()).equals(highlightedWord)) {
|
||||
int s = ClientProxy.Font.width(line.substring(0, m.start()));
|
||||
int e = ClientProxy.Font.width(line.substring(0, m.end())) + 1;
|
||||
drawRect(x + LINE_NUMBER_GUTTER_WIDTH + 1 + s, posY, x + LINE_NUMBER_GUTTER_WIDTH + 1 + e, posY + container.lineHeight, 0x99004c00);
|
||||
|
||||
Reference in new issue
Block a user