mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 17:47:32 +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);
|
||||
|
||||
@@ -99,6 +99,8 @@ public class SearchReplaceBar {
|
||||
*/
|
||||
public interface SearchCallback {
|
||||
String getText();
|
||||
|
||||
String getHighlightedWord();
|
||||
void setText(String text);
|
||||
void scrollToPosition(int position);
|
||||
void setSelection(int start, int end);
|
||||
@@ -134,11 +136,17 @@ public class SearchReplaceBar {
|
||||
showReplace = false;
|
||||
searchFieldFocused = true;
|
||||
replaceFieldFocused = false;
|
||||
if (callback != null) {
|
||||
callback.unfocusMainEditor();
|
||||
String highlight = callback.getHighlightedWord();
|
||||
if (highlight != null) {
|
||||
searchText = highlight;
|
||||
}
|
||||
}
|
||||
searchSelectionStart = 0;
|
||||
searchSelectionEnd = searchText.length();
|
||||
searchCursor = searchText.length();
|
||||
markActivity();
|
||||
if (callback != null) callback.unfocusMainEditor();
|
||||
updateMatches();
|
||||
}
|
||||
|
||||
@@ -146,16 +154,8 @@ public class SearchReplaceBar {
|
||||
* Open search+replace bar (Ctrl+Shift+R)
|
||||
*/
|
||||
public void openSearchReplace() {
|
||||
visible = true;
|
||||
showReplace = true;
|
||||
searchFieldFocused = true;
|
||||
replaceFieldFocused = false;
|
||||
searchSelectionStart = 0;
|
||||
searchSelectionEnd = searchText.length();
|
||||
searchCursor = searchText.length();
|
||||
markActivity();
|
||||
if (callback != null) callback.unfocusMainEditor();
|
||||
updateMatches();
|
||||
openSearch();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user