Skip to content

Commit dc31013

Browse files
frauzufallctrueden
authored andcommitted
searchbar: improve highlighting
1 parent 1927b39 commit dc31013

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/main/java/org/scijava/ui/swing/search/SwingSearchBar.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -622,18 +622,21 @@ private String highlightSearchBold(String text, String search) {
622622
}
623623

624624
private String highlightSearch(String text, String search, String before, String after) {
625+
String[] terms = search.split(" ");
625626
String output = new String(text);
626-
List<Integer> res = new ArrayList<>();
627-
for (int index = output.toLowerCase().indexOf(search); index >= 0;
628-
index = output.toLowerCase().indexOf(search, index + 1)) {
629-
res.add(index);
630-
}
631-
for(int i = res.size()-1; i >= 0; i--) {
632-
int index = res.get(i);
633-
output = output.substring(0, index) + before
634-
+ output.substring(index, index + search.length())
635-
+ after
636-
+ output.substring(index + search.length(), output.length());
627+
for(String term : terms){
628+
List<Integer> res = new ArrayList<>();
629+
for (int index = output.toLowerCase().indexOf(term); index >= 0;
630+
index = output.toLowerCase().indexOf(term, index + 1)) {
631+
res.add(index);
632+
}
633+
for(int i = res.size()-1; i >= 0; i--) {
634+
int index = res.get(i);
635+
output = output.substring(0, index) + before
636+
+ output.substring(index, index + term.length())
637+
+ after
638+
+ output.substring(index + term.length(), output.length());
639+
}
637640
}
638641
return output;
639642
}

0 commit comments

Comments
 (0)