From 1c7f614c3f224b4151f1a38ec6ca74141771d9b6 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Sat, 20 Dec 2025 01:04:31 +0200 Subject: [PATCH] Highlighted search match words if search bar is visible --- .../client/gui/util/GuiScriptTextArea.java | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java index 56cc1d5fc..65fc0680a 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java @@ -440,31 +440,33 @@ public class GuiScriptTextArea extends GuiNpcTextField { } // Highlight search matches - List searchMatches = searchBar.getMatches(); - int currentMatchIdx = searchBar.getCurrentMatchIndex(); - for (int mi = 0; mi < searchMatches.size(); mi++) { - int[] match = searchMatches.get(mi); - // Check if match overlaps with this line - if (match[1] > data.start && match[0] < data.end) { - int matchStart = Math.max(match[0] - data.start, 0); - int matchEnd = Math.min(match[1] - data.start, line.length()); - if (matchStart < matchEnd) { - int s = ClientProxy.Font.width(line.substring(0, matchStart)); - int e = ClientProxy.Font.width(line.substring(0, matchEnd)) + 1; - boolean isExcluded = searchBar.isMatchExcluded(mi); - // Current match gets brighter highlight, others get dimmer - int highlightColor = (mi == currentMatchIdx) ? 0xBB4488ff : 0x662266aa; - if (isExcluded) { - highlightColor = 0x33666666; // Dimmer for excluded matches - } - int highlightX = x + LINE_NUMBER_GUTTER_WIDTH + 1 + s; - int highlightEndX = x + LINE_NUMBER_GUTTER_WIDTH + 1 + e; - drawRect(highlightX, posY, highlightEndX, posY + container.lineHeight, highlightColor); - - // Draw strikethrough line for excluded matches - if (isExcluded) { - int strikeY = posY + container.lineHeight / 2; - drawRect(highlightX, strikeY, highlightEndX, strikeY + 1, 0xFFaa4444); + if (searchBar.isVisible()) { + List searchMatches = searchBar.getMatches(); + int currentMatchIdx = searchBar.getCurrentMatchIndex(); + for (int mi = 0; mi < searchMatches.size(); mi++) { + int[] match = searchMatches.get(mi); + // Check if match overlaps with this line + if (match[1] > data.start && match[0] < data.end) { + int matchStart = Math.max(match[0] - data.start, 0); + int matchEnd = Math.min(match[1] - data.start, line.length()); + if (matchStart < matchEnd) { + int s = ClientProxy.Font.width(line.substring(0, matchStart)); + int e = ClientProxy.Font.width(line.substring(0, matchEnd)) + 1; + boolean isExcluded = searchBar.isMatchExcluded(mi); + // Current match gets brighter highlight, others get dimmer + int highlightColor = (mi == currentMatchIdx) ? 0xBB4488ff : 0x662266aa; + if (isExcluded) { + highlightColor = 0x33666666; // Dimmer for excluded matches + } + int highlightX = x + LINE_NUMBER_GUTTER_WIDTH + 1 + s; + int highlightEndX = x + LINE_NUMBER_GUTTER_WIDTH + 1 + e; + drawRect(highlightX, posY, highlightEndX, posY + container.lineHeight, highlightColor); + + // Draw strikethrough line for excluded matches + if (isExcluded) { + int strikeY = posY + container.lineHeight / 2; + drawRect(highlightX, strikeY, highlightEndX, strikeY + 1, 0xFFaa4444); + } } } }