Skip to content

Commit

Permalink
Fix focus for keywords and crossref fields (#11792)
Browse files Browse the repository at this point in the history
  • Loading branch information
LoayGhreeb authored Sep 20, 2024
1 parent 4e864f6 commit ec62ec0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,16 +38,16 @@

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<Keyword> keywordTagsField;

@Inject private CliPreferences preferences;
@Inject private DialogService dialogService;
@Inject private UndoManager undoManager;
@Inject private ClipBoardManager clipBoardManager;

private final KeywordsEditorViewModel viewModel;

public KeywordsEditor(Field field,
SuggestionProvider<?> suggestionProvider,
FieldCheckers fieldCheckers) {
Expand All @@ -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 -> {
Expand Down Expand Up @@ -118,11 +121,6 @@ public Parent getNode() {
return this;
}

@Override
public void requestFocus() {
keywordTagsField.requestFocus();
}

@Override
public double getWeight() {
return 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ParsedEntryLink> entryLinkField;
@FXML private LinkedEntriesEditorViewModel viewModel;
@FXML private TagsField<ParsedEntryLink> 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)
Expand All @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,6 +19,7 @@
import com.dlsc.gemsfx.TagsField;

public class AutoCompletionTab extends AbstractPreferenceTabView<AutoCompletionTabViewModel> implements PreferencesTab {
private static final PseudoClass FOCUSED = PseudoClass.getPseudoClass("focused");

@FXML private CheckBox enableAutoComplete;
@FXML private TagsField<Field> autoCompleteFields;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ec62ec0

Please sign in to comment.