From ec62ec0fae346d25e174ab7ce0a94bda5a898aa1 Mon Sep 17 00:00:00 2001 From: Loay Ghreeb Date: Fri, 20 Sep 2024 18:39:48 +0300 Subject: [PATCH] Fix focus for keywords and crossref fields (#11792) --- CHANGELOG.md | 1 + src/main/java/org/jabref/gui/Base.css | 13 +++++++------ .../org/jabref/gui/fieldeditors/KeywordsEditor.java | 12 +++++------- .../gui/fieldeditors/LinkedEntriesEditor.java | 11 +++++++---- .../autocompletion/AutoCompletionTab.java | 4 ++++ 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b191b87606c..320ed820875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an exception when searching for unlinked files. [#11731](https://github.com/JabRef/jabref/issues/11731) - We fixed an issue where two contradicting notifications were shown when cutting an entry in the main table. [#11724](https://github.com/JabRef/jabref/pull/11724) - We fixed an issue where unescaped braces in the arXiv fetcher were not treated. [#11704](https://github.com/JabRef/jabref/issues/11704) +- We fixed an issue where the keywords and crossref fields were not properly focused. [#11177](https://github.com/JabRef/jabref/issues/11177) ### Removed diff --git a/src/main/java/org/jabref/gui/Base.css b/src/main/java/org/jabref/gui/Base.css index 3832348936a..14ae1873d4a 100644 --- a/src/main/java/org/jabref/gui/Base.css +++ b/src/main/java/org/jabref/gui/Base.css @@ -1427,17 +1427,15 @@ We want to have a look that matches our icons in the tool-bar */ -fx-label-padding: 5 0 10 10; } -.chips-pane > .editor { +.tags-field { -fx-pref-height: 30px; - -fx-padding: 0px 0px 0px -8px; -fx-margin: 0em; -fx-border-style: none; + -fx-background-color: -fx-outer-border, -fx-control-inner-background; } -.tags-field { - -fx-pref-height: 30px; - -fx-margin: 0em; - -fx-border-style: none; +.tags-field:focused { + -fx-border-color: -jr-accent; } .tags-field > .flow-pane > .tag-view { @@ -1452,6 +1450,9 @@ We want to have a look that matches our icons in the tool-bar */ .tags-field-editor { -fx-border-width: 0; + -fx-text-fill: -fx-focused-text-base-color; + -fx-highlight-text-fill: -fx-text-inner-color; + -fx-highlight-fill: derive(-jr-accent, 20%); } .searchBar:invalid { diff --git a/src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java b/src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java index f06cbc42989..4da18163ab2 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java @@ -5,6 +5,7 @@ import javax.swing.undo.UndoManager; import javafx.beans.binding.Bindings; +import javafx.css.PseudoClass; import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.Parent; @@ -37,7 +38,9 @@ public class KeywordsEditor extends HBox implements FieldEditorFX { private static final Logger LOGGER = LoggerFactory.getLogger(KeywordsEditor.class); + private static final PseudoClass FOCUSED = PseudoClass.getPseudoClass("focused"); + @FXML private KeywordsEditorViewModel viewModel; @FXML private TagsField keywordTagsField; @Inject private CliPreferences preferences; @@ -45,8 +48,6 @@ public class KeywordsEditor extends HBox implements FieldEditorFX { @Inject private UndoManager undoManager; @Inject private ClipBoardManager clipBoardManager; - private final KeywordsEditorViewModel viewModel; - public KeywordsEditor(Field field, SuggestionProvider suggestionProvider, FieldCheckers fieldCheckers) { @@ -73,8 +74,10 @@ public KeywordsEditor(Field field, keywordTagsField.setNewItemProducer(searchText -> viewModel.getStringConverter().fromString(searchText)); keywordTagsField.setShowSearchIcon(false); + keywordTagsField.setOnMouseClicked(event -> keywordTagsField.getEditor().requestFocus()); keywordTagsField.getEditor().getStyleClass().clear(); keywordTagsField.getEditor().getStyleClass().add("tags-field-editor"); + keywordTagsField.getEditor().focusedProperty().addListener((observable, oldValue, newValue) -> keywordTagsField.pseudoClassStateChanged(FOCUSED, newValue)); String keywordSeparator = String.valueOf(viewModel.getKeywordSeparator()); keywordTagsField.getEditor().setOnKeyReleased(event -> { @@ -118,11 +121,6 @@ public Parent getNode() { return this; } - @Override - public void requestFocus() { - keywordTagsField.requestFocus(); - } - @Override public double getWeight() { return 2; diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java index 0dd4ace6b99..4b65ad78349 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedEntriesEditor.java @@ -5,6 +5,7 @@ import javax.swing.undo.UndoManager; import javafx.beans.binding.Bindings; +import javafx.css.PseudoClass; import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.Parent; @@ -39,18 +40,17 @@ import org.slf4j.LoggerFactory; public class LinkedEntriesEditor extends HBox implements FieldEditorFX { - private static final Logger LOGGER = LoggerFactory.getLogger(LinkedEntriesEditor.class); + private static final PseudoClass FOCUSED = PseudoClass.getPseudoClass("focused"); - @FXML public TagsField entryLinkField; + @FXML private LinkedEntriesEditorViewModel viewModel; + @FXML private TagsField entryLinkField; @Inject private DialogService dialogService; @Inject private ClipBoardManager clipBoardManager; @Inject private UndoManager undoManager; @Inject private StateManager stateManager; - private final LinkedEntriesEditorViewModel viewModel; - public LinkedEntriesEditor(Field field, BibDatabaseContext databaseContext, SuggestionProvider suggestionProvider, FieldCheckers fieldCheckers) { ViewLoader.view(this) .root(this) @@ -66,9 +66,12 @@ public LinkedEntriesEditor(Field field, BibDatabaseContext databaseContext, Sugg entryLinkField.setNewItemProducer(searchText -> viewModel.getStringConverter().fromString(searchText)); entryLinkField.setMatcher((entryLink, searchText) -> entryLink.getKey().toLowerCase().startsWith(searchText.toLowerCase())); entryLinkField.setComparator(Comparator.comparing(ParsedEntryLink::getKey)); + entryLinkField.setShowSearchIcon(false); + entryLinkField.setOnMouseClicked(event -> entryLinkField.getEditor().requestFocus()); entryLinkField.getEditor().getStyleClass().clear(); entryLinkField.getEditor().getStyleClass().add("tags-field-editor"); + entryLinkField.getEditor().focusedProperty().addListener((observable, oldValue, newValue) -> entryLinkField.pseudoClassStateChanged(FOCUSED, newValue)); String separator = EntryLinkList.SEPARATOR; entryLinkField.getEditor().setOnKeyReleased(event -> { diff --git a/src/main/java/org/jabref/gui/preferences/autocompletion/AutoCompletionTab.java b/src/main/java/org/jabref/gui/preferences/autocompletion/AutoCompletionTab.java index 4b02b535df3..d8837eb0443 100644 --- a/src/main/java/org/jabref/gui/preferences/autocompletion/AutoCompletionTab.java +++ b/src/main/java/org/jabref/gui/preferences/autocompletion/AutoCompletionTab.java @@ -1,5 +1,6 @@ package org.jabref.gui.preferences.autocompletion; +import javafx.css.PseudoClass; import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.CheckBox; @@ -18,6 +19,7 @@ import com.dlsc.gemsfx.TagsField; public class AutoCompletionTab extends AbstractPreferenceTabView implements PreferencesTab { + private static final PseudoClass FOCUSED = PseudoClass.getPseudoClass("focused"); @FXML private CheckBox enableAutoComplete; @FXML private TagsField autoCompleteFields; @@ -58,8 +60,10 @@ private void setupTagsFiled() { autoCompleteFields.setConverter(viewModel.getFieldStringConverter()); autoCompleteFields.setTagViewFactory(this::createTag); autoCompleteFields.setShowSearchIcon(false); + autoCompleteFields.setOnMouseClicked(event -> autoCompleteFields.getEditor().requestFocus()); autoCompleteFields.getEditor().getStyleClass().clear(); autoCompleteFields.getEditor().getStyleClass().add("tags-field-editor"); + autoCompleteFields.getEditor().focusedProperty().addListener((observable, oldValue, newValue) -> autoCompleteFields.pseudoClassStateChanged(FOCUSED, newValue)); } private Node createTag(Field field) {