Fix the ESC key for GlobalSearchResultDialog#15259
Conversation
Review Summary by QodoFix ESC key behavior in global search dialog
WalkthroughsDescription• Fix ESC key behavior in global search dialog • Clear search field only when it contains text • Close dialog on subsequent ESC press after clearing • Apply consistent logic across search components Diagramflowchart LR
A["ESC key pressed"] --> B{"Search field empty?"}
B -->|No| C["Clear search field"]
C --> D["Consume event"]
B -->|Yes| E["Close dialog"]
File Changes1. jabgui/src/main/java/org/jabref/gui/search/GlobalSearchBar.java
|
Code Review by Qodo
1.
|
| searchField.addEventFilter(KeyEvent.KEY_PRESSED, event -> { | ||
| if (keyBindingRepository.matches(event, KeyBinding.CLEAR_SEARCH)) { | ||
| searchField.clear(); | ||
| if (searchType == SearchType.NORMAL_SEARCH) { | ||
| LibraryTab currentLibraryTab = tabContainer.getCurrentLibraryTab(); | ||
| if (currentLibraryTab != null) { | ||
| currentLibraryTab.getMainTable().requestFocus(); | ||
| if (!searchField.getText().isEmpty()) { | ||
| searchField.clear(); | ||
| if (searchType == SearchType.NORMAL_SEARCH) { | ||
| LibraryTab currentLibraryTab = tabContainer.getCurrentLibraryTab(); | ||
| if (currentLibraryTab != null) { | ||
| currentLibraryTab.getMainTable().requestFocus(); | ||
| } | ||
| } | ||
| event.consume(); | ||
| } | ||
| event.consume(); | ||
| } |
There was a problem hiding this comment.
2. Esc behavior lacks tests 📘 Rule violation ⛯ Reliability
The PR changes CLEAR_SEARCH/ESC key handling in the global search field but does not add/update tests to cover the new behavior. This increases regression risk for an interaction-heavy UI behavior.
Agent Prompt
## Issue description
Key handling behavior for CLEAR_SEARCH/ESC was changed, but the PR does not add/update tests to cover the new interaction.
## Issue Context
This is a UI interaction with potential regressions. JabRef already uses TestFX in `jabgui` tests, so adding coverage should be feasible.
## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/search/GlobalSearchBar.java[151-163]
- jabgui/src/main/java/org/jabref/gui/search/SearchTextField.java[26-37]
- jabgui/src/test/java/org/jabref/gui/search/GlobalSearchBarTest.java[1-119]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| searchField.addEventFilter(KeyEvent.KEY_PRESSED, event -> { | ||
| if (keyBindingRepository.matches(event, KeyBinding.CLEAR_SEARCH)) { | ||
| searchField.clear(); | ||
| if (searchType == SearchType.NORMAL_SEARCH) { | ||
| LibraryTab currentLibraryTab = tabContainer.getCurrentLibraryTab(); | ||
| if (currentLibraryTab != null) { | ||
| currentLibraryTab.getMainTable().requestFocus(); | ||
| if (!searchField.getText().isEmpty()) { | ||
| searchField.clear(); | ||
| if (searchType == SearchType.NORMAL_SEARCH) { | ||
| LibraryTab currentLibraryTab = tabContainer.getCurrentLibraryTab(); | ||
| if (currentLibraryTab != null) { | ||
| currentLibraryTab.getMainTable().requestFocus(); | ||
| } | ||
| } | ||
| event.consume(); | ||
| } | ||
| event.consume(); | ||
| } |
There was a problem hiding this comment.
3. Esc empty won't refocus table 🐞 Bug ✓ Correctness
In NORMAL_SEARCH mode, pressing ESC when the search field is already empty will no longer request focus on the main table (and the key event is no longer consumed). This can break the expected “ESC leaves search / returns to table” workflow and may allow the ESC key to trigger higher-level handlers unintentionally.
Agent Prompt
### Issue description
In `GlobalSearchBar`, the CLEAR_SEARCH (Esc) handler is now guarded by `!searchField.getText().isEmpty()`. This means that when the field is already empty, the handler does not run, so NORMAL_SEARCH no longer refocuses the main table on Esc.
### Issue Context
This PR aims to allow Esc to close the global search dialog when the input is empty (by not consuming Esc in that case). That behavior should be preserved for GLOBAL_SEARCH, but NORMAL_SEARCH likely still benefits from treating Esc as “leave search” even when already empty.
### Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/search/GlobalSearchBar.java[151-164]
- jabgui/src/main/java/org/jabref/gui/search/SearchTextField.java[26-37]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ All tests passed ✅🏷️ Commit: cced61e Learn more about TestLens at testlens.app. |
* upstream/main: (59 commits) Fix 15000 identifier (JabRef#15286) Chore(deps): Bump dev.langchain4j:langchain4j-bom in /versions (JabRef#15305) Supress JavaFX VirtualFlow Info log noise for large libraries (10k+). (JabRef#15298) Chore(deps): Bump commons-logging:commons-logging in /versions (JabRef#15304) Fix merge dialog closing immediately when only one PDF importer returns metadata (JabRef#15127) (JabRef#15287) Fixed nullable eventhandlers (JabRef#15288) New Crowdin updates (JabRef#15285) Fix the ESC key for GlobalSearchResultDialog (JabRef#15259) Remove jbang plugin banner (JabRef#15282) Chore(deps): Bump org.apache.httpcomponents.core5:httpcore5 in /versions (JabRef#15281) Udpate to latest gradle master (JabRef#15279) Migrate to GemsFX Notifications (JabRef#14762) Chore(deps): Bump JetBrains/junie-github-action from 0 to 1 (JabRef#15272) Chore(deps): Bump docker/setup-qemu-action from 3 to 4 (JabRef#15269) Feature/citation count dropdown (JabRef#15216) Update dependency org.apache.maven.plugins:maven-resources-plugin to v3.5.0 (JabRef#15275) Chore(deps): Bump jablib/src/main/resources/csl-styles (JabRef#15273) Fix more security Fix pr_body leakage Chore: add dependency-management.md (JabRef#15278) ...
Fixes #15133
This PR fixes the behavior of the ESC key for the global search bar. On the first press, it clears the input field, and on the next press, it closes the dialog.
expected_behavior.mov
Steps to test
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)