Skip to content

Commit

Permalink
Commit new keyword when typing the keywords separator (JabRef#11187)
Browse files Browse the repository at this point in the history
* Add a keyword when using the keyword separator

* Add crossref when using the EntryLink separator

* Update CHANGELOG.md

* Update CHANGELOG.md
  • Loading branch information
LoayGhreeb authored Apr 11, 2024
1 parent 66a77cd commit 8329b82
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added a new keyboard shortcut <kbd>ctrl</kbd> + <kbd>,</kbd> to open the preferences. [#11154](https://github.com/JabRef/jabref/pull/11154)
- We added value selection (such as for month) for content selectors in custom entry types. [#11109](https://github.com/JabRef/jabref/issues/11109)
- We added tooltip on main table cells that shows cell content or cell content and entry preview if set in preferences. [10925](https://github.com/JabRef/jabref/issues/10925)
- We added the ability to add a keyword/crossref when typing the separator character (e.g., comma) in the keywords/crossref fields. [#11178](https://github.com/JabRef/jabref/issues/11178)

### Changed

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/gui/fieldeditors/KeywordsEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public KeywordsEditor(Field field,
keywordTagsField.getEditor().getStyleClass().clear();
keywordTagsField.getEditor().getStyleClass().add("tags-field-editor");

String keywordSeparator = String.valueOf(viewModel.getKeywordSeparator());
keywordTagsField.getEditor().setOnKeyReleased(event -> {
if (event.getText().equals(keywordSeparator)) {
keywordTagsField.commit();
event.consume();
}
});

Bindings.bindContentBidirectional(keywordTagsField.getTags(), viewModel.keywordListProperty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ public List<Keyword> getSuggestions(String request) {

return suggestions;
}

public Character getKeywordSeparator() {
return keywordSeparator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.EntryLinkList;
import org.jabref.model.entry.ParsedEntryLink;
import org.jabref.model.entry.field.Field;

Expand Down Expand Up @@ -71,6 +72,14 @@ public LinkedEntriesEditor(Field field, BibDatabaseContext databaseContext, Sugg
entryLinkField.getEditor().getStyleClass().clear();
entryLinkField.getEditor().getStyleClass().add("tags-field-editor");

String separator = EntryLinkList.SEPARATOR;
entryLinkField.getEditor().setOnKeyReleased(event -> {
if (event.getText().equals(separator)) {
entryLinkField.commit();
event.consume();
}
});

Bindings.bindContentBidirectional(entryLinkField.getTags(), viewModel.linkedEntriesProperty());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/model/entry/EntryLinkList.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class EntryLinkList {

private static String SEPARATOR = ",";
public static final String SEPARATOR = ",";

private EntryLinkList() {
}
Expand All @@ -26,6 +26,6 @@ public static List<ParsedEntryLink> parse(String fieldValue, BibDatabase databas
}

public static String serialize(List<ParsedEntryLink> list) {
return String.join(SEPARATOR, list.stream().map(ParsedEntryLink::getKey).collect(Collectors.toList()));
return list.stream().map(ParsedEntryLink::getKey).collect(Collectors.joining(SEPARATOR));
}
}

0 comments on commit 8329b82

Please sign in to comment.