Skip to content

Commit

Permalink
Highlight search bar on wrong syntax (JabRef#11658)
Browse files Browse the repository at this point in the history
* Highlight search bar on wrong syntax

* Update CHANGELOG.md
  • Loading branch information
LoayGhreeb authored Aug 21, 2024
1 parent 8c51e7a commit f4e87e5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- The dialog for [adding an entry using reference text](https://docs.jabref.org/collect/newentryfromplaintext) is now filled with the clipboard contents as default. [#11565](https://github.com/JabRef/jabref/pull/11565)
- Added minimal support for [biblatex data annotation](https://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf#subsection.3.7) fields in `.layout` files. [#11505](https://github.com/JabRef/jabref/issues/11505)
- Added saving of selected options in the [Lookup -> Search for unlinked local files dialog](https://docs.jabref.org/collect/findunlinkedfiles#link-the-pdfs-to-your-bib-library). [#11439](https://github.com/JabRef/jabref/issues/11439)
- We fixed ans issue where text in Dark mode inside "Citation information" was not readable [#11512](https://github.com/JabRef/jabref/issues/11512)
- We enabled creating a new file link manually. [#11017](https://github.com/JabRef/jabref/issues/11017)
- We added a toggle button to invert the selected groups. [#9073](https://github.com/JabRef/jabref/issues/9073)
- We reintroduced the floating search in the main table. [#4237](https://github.com/JabRef/jabref/issues/4237)
- We fixed an issue where the selection of an entry in the table lost after searching for a group. [#3176](https://github.com/JabRef/jabref/issues/3176)
- We added a different background color to the search bar to indicate when the search syntax is wrong. [#11658](https://github.com/JabRef/jabref/pull/11658)

### Changed

Expand All @@ -49,6 +48,8 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where a new unsaved library was not marked with an asterisk. [#11519](https://github.com/JabRef/jabref/pull/11519)
- We fixed an issue where JabRef starts without window decorations. [#11440](https://github.com/JabRef/jabref/pull/11440)
- We fixed an issue where the entry preview highlight was not working when searching before opening the entry editor. [#11659](https://github.com/JabRef/jabref/pull/11659)
- We fixed an issue where text in Dark mode inside "Citation information" was not readable. [#11512](https://github.com/JabRef/jabref/issues/11512)
- We fixed an issue where the selection of an entry in the table lost after searching for a group. [#3176](https://github.com/JabRef/jabref/issues/3176)

### Removed

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,10 @@ TextFlow > .tooltip-text-monospaced {
-fx-padding: 0em 1.8em 0em 0em;
}

.global-search-bar:illegal-search {
-fx-background-color: derive(-jr-light-red, 70%);
}

/* The little arrow that shows up when not all tool-bar icons fit into the tool-bar.
We want to have a look that matches our icons in the tool-bar */
.mainToolbar .tool-bar-overflow-button > .arrow {
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@
public class GlobalSearchBar extends HBox {

private static final Logger LOGGER = LoggerFactory.getLogger(GlobalSearchBar.class);

private static final int SEARCH_DELAY = 400;
private static final PseudoClass CLASS_NO_RESULTS = PseudoClass.getPseudoClass("emptyResult");
private static final PseudoClass CLASS_RESULTS_FOUND = PseudoClass.getPseudoClass("emptyResult");
private static final PseudoClass ILLEGAL_SEARCH = PseudoClass.getPseudoClass("illegal-search");

private final CustomTextField searchField;
private final ToggleButton caseSensitiveButton;
Expand Down Expand Up @@ -126,22 +124,24 @@ public GlobalSearchBar(LibraryTabContainer tabContainer,
Label currentResults = new Label();
// fits the standard "found x entries"-message thus hinders the searchbar to jump around while searching if the tabContainer width is too small
currentResults.setPrefWidth(150);
currentResults.visibleProperty().bind(stateManager.activeSearchQuery(searchType).isPresent());

currentResults.textProperty().bind(EasyBind.combine(
stateManager.searchResultSize(searchType), illegalSearch, invalidRegex,
(matched, illegal, invalid) -> {
stateManager.activeSearchQuery(searchType), stateManager.searchResultSize(searchType), illegalSearch, invalidRegex,
(searchQuery, matched, illegal, invalid) -> {
if (illegal) {
searchField.pseudoClassStateChanged(CLASS_NO_RESULTS, true);
searchField.pseudoClassStateChanged(ILLEGAL_SEARCH, true);
return Localization.lang("Search failed: illegal search expression");
} else if (invalid) {
searchField.pseudoClassStateChanged(CLASS_NO_RESULTS, true);
searchField.pseudoClassStateChanged(ILLEGAL_SEARCH, true);
return Localization.lang("Invalid regular expression");
} else if (searchQuery.isEmpty()) {
searchField.pseudoClassStateChanged(ILLEGAL_SEARCH, false);
return "";
} else if (matched.intValue() == 0) {
searchField.pseudoClassStateChanged(CLASS_NO_RESULTS, true);
searchField.pseudoClassStateChanged(ILLEGAL_SEARCH, false);
return Localization.lang("No results found.");
} else {
searchField.pseudoClassStateChanged(CLASS_RESULTS_FOUND, true);
searchField.pseudoClassStateChanged(ILLEGAL_SEARCH, false);
return Localization.lang("Found %0 results.", String.valueOf(matched));
}
}
Expand Down Expand Up @@ -338,6 +338,8 @@ public void updateSearchQuery() {
if (searchField.getText().isEmpty()) {
setSearchFieldHintTooltip(null);
stateManager.activeSearchQuery(searchType).set(Optional.empty());
illegalSearch.set(false);
invalidRegex.set(false);
return;
}

Expand Down

0 comments on commit f4e87e5

Please sign in to comment.