Skip to content

Commit 03865a9

Browse files
committed
Close the search on execution only as appropriate
When pressing ENTER, in some cases, there is nothing to do. In those cases, let's not close the search pane prematurely. Furthermore, some actions do not want the search pane to close in response to being executed. Let's respect that, too. Thanks to Jan Eglinger for noticing.
1 parent b12bce9 commit 03865a9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ private void search() {
307307
/** Called when the user hits ENTER. */
308308
private void run() {
309309
assertDispatchThread();
310-
searchPanel.execute();
311-
reset();
310+
final boolean closeSearch = searchPanel.execute();
311+
if (closeSearch) reset();
312312
}
313313

314314
private void reset() {
@@ -610,7 +610,7 @@ private Font smaller(final Font font, final int decrement) {
610610
}
611611

612612
/** Executes the default search action. */
613-
private void execute() {
613+
private boolean execute() {
614614
assertDispatchThread();
615615

616616
// Figure out which result to execute.
@@ -619,14 +619,16 @@ private void execute() {
619619
if (selectedResult == null) {
620620
// Nothing is selected; use the first result on the list.
621621
final int firstResultIndex = firstResultIndex();
622-
if (firstResultIndex < 0) return; // no results available
622+
if (firstResultIndex < 0) return false; // no results available
623623
result = result(firstResultIndex);
624624
}
625625
else result = selectedResult;
626626

627627
final List<SearchAction> actions = searchService.actions(result);
628-
if (actions.isEmpty()) return;
629-
threadService.run(() -> actions.get(0).run());
628+
if (actions.isEmpty()) return false;
629+
final SearchAction action = actions.get(0);
630+
threadService.run(() -> action.run());
631+
return action.closesSearch();
630632
}
631633

632634
private void rebuild() {

0 commit comments

Comments
 (0)