Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve search history by attaching change listener #9794

Merged
merged 20 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where searching for unlinked files would include the current library's .bib file [#9735](https://github.com/JabRef/jabref/issues/9735)
- We fixed an issue where it was no longer possible to connect to a shared mysql database due to an exception [#9761](https://github.com/JabRef/jabref/issues/9761)
- We fixed the citation key generation for (`[authors]`, `[authshort]`, `[authorsAlpha]`, `authIniN`, `authEtAl`, `auth.etal`)[https://docs.jabref.org/setup/citationkeypatterns#special-field-markers] to handle `and others` properly. [koppor#626](https://github.com/koppor/jabref/issues/626)
- We fixed an issue regarding recording redundant prefixes in search history, by attaching a change listener on the focus property of search box. [#9685](https://github.com/JabRef/jabref/issues/9685)
dkokkotas marked this conversation as resolved.
Show resolved Hide resolved

### Removed

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, Preferences

this.stateManager.activeSearchQueryProperty().addListener((obs, oldvalue, newValue) -> newValue.ifPresent(this::updateSearchResultsForQuery));
this.stateManager.activeDatabaseProperty().addListener((obs, oldValue, newValue) -> stateManager.activeSearchQueryProperty().get().ifPresent(this::updateSearchResultsForQuery));
/*
* The listener tracks a change on the focus property value.
* This happens, from active (user types a query) to inactive / focus
* lost (e.g., user selects an entry or triggers the search).
* The search history should only be filled, if focus is lost.
*/
searchField.focusedProperty().addListener((obs, oldValue, newValue) -> {
// Focus lost can be derived by checking that there is no newValue (or the text is empty)
if (oldValue && !(newValue || searchField.getText().isBlank())) {
this.stateManager.addSearchHistory(searchField.textProperty().get());
}
});
}

private void updateSearchResultsForQuery(SearchQuery query) {
Expand Down Expand Up @@ -307,7 +319,6 @@ public void performSearch() {
informUserAboutInvalidSearchQuery();
return;
}
this.stateManager.addSearchHistory(searchField.textProperty().get());
stateManager.setSearchQuery(searchQuery);
}

Expand Down