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

Highlight search bar on wrong syntax #11658

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Highlight search bar on wrong syntax
  • Loading branch information
LoayGhreeb committed Aug 20, 2024
commit 0d62c9c4b7a82c1d4ec7af8518cff3a6f4f482fc
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