mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 18:57:32 +00:00
SearchReplaceBar QoL:
* Shifted text editor viewport appropriately when opening/closing bar * Bar is now maintained across multiple script tabs with its focus * Can open bar without having main editor viewport focused
This commit is contained in:
1 parent
9a03ccf569
commit
85b2fe24a2
2 files changed
+39
-11
No files matched your search
@@ -161,6 +161,14 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
public void onMatchesUpdated() {
|
||||
// Called when matches change - could be used for UI updates
|
||||
}
|
||||
|
||||
// Shift text editor viewport up or down bar
|
||||
public void resizeEditor(boolean open) {
|
||||
int scrollHeight = searchBar.getTotalHeight();
|
||||
GuiScriptTextArea.this.y += open ? scrollHeight : -scrollHeight;
|
||||
GuiScriptTextArea.this.height += open ? -scrollHeight : scrollHeight;
|
||||
container.visibleLines = Math.max(GuiScriptTextArea.this.height / container.lineHeight - 1, 1);
|
||||
}
|
||||
});
|
||||
// Initialize Go To Line dialog with callback
|
||||
this.goToLineDialog = new GoToLineDialog(new GoToLineDialog.GoToLineCallback() {
|
||||
@@ -247,6 +255,12 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
|
||||
// Initialize search bar (preserves state across initGui calls)
|
||||
searchBar.initGui(x, y, width);
|
||||
if (searchBar.isVisible()) { // If open
|
||||
// Shift viewport down again
|
||||
searchBar.callback.resizeEditor(true);
|
||||
if (!active) // Focus search if opening another script tab & bar is open
|
||||
searchBar.focus(false);
|
||||
}
|
||||
|
||||
// Initialize Go To Line dialog
|
||||
goToLineDialog.initGui(x, y, width);
|
||||
@@ -587,8 +601,6 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
goToLineDialog.draw(xMouse, yMouse);
|
||||
|
||||
KEYS_OVERLAY.draw(xMouse, yMouse, wheelDelta);
|
||||
// y -= searchHeight;
|
||||
// height += searchHeight;
|
||||
}
|
||||
|
||||
private void scissorViewport() {
|
||||
@@ -855,11 +867,15 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Check if can open just for SearchReplaceBar and GoToLine
|
||||
Supplier<Boolean> openBoxes = () -> !KEYS_OVERLAY.showOverlay;
|
||||
|
||||
// SEARCH: Open search bar (Ctrl+R)
|
||||
// Works in search bar.
|
||||
KEYS.SEARCH.setTask(e -> {
|
||||
if (!e.isPress() || !isActive.get() && !searchBar.isVisible())
|
||||
if (!e.isPress() || !openBoxes.get())
|
||||
return;
|
||||
|
||||
unfocusAll();
|
||||
@@ -869,7 +885,7 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
// SEARCH_REPLACE: Open search+replace bar (Ctrl+Shift+R)
|
||||
// Works in search bar.
|
||||
KEYS.SEARCH_REPLACE.setTask(e -> {
|
||||
if (!e.isPress() || !isActive.get() && !searchBar.isVisible())
|
||||
if (!e.isPress() || !openBoxes.get())
|
||||
return;
|
||||
|
||||
unfocusAll();
|
||||
@@ -879,7 +895,7 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
// GO_TO_LINE: Open go to line dialog (Ctrl+G)
|
||||
// Works in search bar.
|
||||
KEYS.GO_TO_LINE.setTask(e -> {
|
||||
if (!e.isPress() || !isActive.get() && !searchBar.isVisible())
|
||||
if (!e.isPress() || !openBoxes.get())
|
||||
return;
|
||||
|
||||
unfocusAll();
|
||||
|
||||
@@ -98,7 +98,7 @@ public class SearchReplaceBar {
|
||||
private boolean lastClickWasSearch = true;
|
||||
|
||||
// ==================== CALLBACK ====================
|
||||
private SearchCallback callback;
|
||||
public SearchCallback callback;
|
||||
|
||||
private final FontRenderer font = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
@@ -116,6 +116,7 @@ public class SearchReplaceBar {
|
||||
void unfocusMainEditor();
|
||||
void focusMainEditor();
|
||||
void onMatchesUpdated(); // Called when matches change (for undo/redo sync)
|
||||
void resizeEditor(boolean open);
|
||||
}
|
||||
|
||||
public SearchReplaceBar() {
|
||||
@@ -140,16 +141,18 @@ public class SearchReplaceBar {
|
||||
* Open search bar (Ctrl+R)
|
||||
*/
|
||||
public void openSearch() {
|
||||
boolean oldVisible = this.visible;
|
||||
visible = true;
|
||||
showReplace = false;
|
||||
searchFieldFocused = true;
|
||||
replaceFieldFocused = false;
|
||||
if (callback != null) {
|
||||
if (!oldVisible) //if wasnt open before, do it once.
|
||||
callback.resizeEditor(true);
|
||||
callback.unfocusMainEditor();
|
||||
String highlight = callback.getHighlightedWord();
|
||||
if (highlight != null) {
|
||||
if (highlight != null)
|
||||
searchText = highlight;
|
||||
}
|
||||
}
|
||||
searchSelectionStart = 0;
|
||||
searchSelectionEnd = searchText.length();
|
||||
@@ -170,12 +173,21 @@ public class SearchReplaceBar {
|
||||
* Close the search bar and restore focus to main editor
|
||||
*/
|
||||
public void close() {
|
||||
if (callback != null) {
|
||||
callback.resizeEditor(false);
|
||||
callback.focusMainEditor();
|
||||
}
|
||||
visible = false;
|
||||
searchFieldFocused = false;
|
||||
replaceFieldFocused = false;
|
||||
if (callback != null) callback.focusMainEditor();
|
||||
}
|
||||
|
||||
|
||||
public void focus(boolean replace) {
|
||||
if (replace)
|
||||
replaceFieldFocused = true;
|
||||
else
|
||||
searchFieldFocused = true;
|
||||
}
|
||||
/**
|
||||
* Unfocus the search bar (when clicking main editor)
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user