Skip to content

Commit

Permalink
Fix display bug for keyword groups with empty keywords (#5347)
Browse files Browse the repository at this point in the history
Fix display bug for keyword groups with empty keywords
  • Loading branch information
koppor authored Oct 2, 2019
2 parents 631cec5 + dc4efcb commit 96037df
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- After assigning an entry to a group, the item count is now properly colored to reflect the new membership of the entry. [#3112](https://github.com/JabRef/jabref/issues/3112)
- The group panel is now properly updated when switching between libraries (or when closing/opening one). [#3142](https://github.com/JabRef/jabref/issues/3142)
- We fixed an error where the number of matched entries shown in the group pane was not updated correctly. [#4441](https://github.com/JabRef/jabref/issues/4441)
- We fixed an issue where empty keywords lead to a strange display of automatic keyword groups. [#5333](https://github.com/JabRef/jabref/issues/5333)
- We fixed an error where the default color of a new group was white instead of dark gray. [#4868](https://github.com/JabRef/jabref/issues/4868)
- We fixed an error mentioning "javafx.controls/com.sun.javafx.scene.control" that was thrown when interacting with the toolbar.
- We fixed an error where a cleared search was restored after switching libraries. [#4846](https://github.com/JabRef/jabref/issues/4846)
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jabref.model.entry.Keyword;
import org.jabref.model.entry.KeywordList;
import org.jabref.model.entry.field.Field;
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.OptionalUtil;

public class AutomaticKeywordGroup extends AutomaticGroup {
Expand Down Expand Up @@ -62,11 +63,12 @@ public int hashCode() {
@Override
public Set<GroupTreeNode> createSubgroups(BibEntry entry) {
Optional<KeywordList> keywordList = entry.getLatexFreeField(field)
.map(fieldValue -> KeywordList.parse(fieldValue, keywordDelimiter));
.map(fieldValue -> KeywordList.parse(fieldValue, keywordDelimiter));
return OptionalUtil.toStream(keywordList)
.flatMap(KeywordList::stream)
.map(this::createGroup)
.collect(Collectors.toSet());
.flatMap(KeywordList::stream)
.filter(keyword -> StringUtil.isNotBlank(keyword.get()))
.map(this::createGroup)
.collect(Collectors.toSet());
}

private GroupTreeNode createGroup(Keyword keywordChain) {
Expand All @@ -80,8 +82,8 @@ private GroupTreeNode createGroup(Keyword keywordChain) {
true);
GroupTreeNode root = new GroupTreeNode(rootGroup);
keywordChain.getChild()
.map(this::createGroup)
.ifPresent(root::addChild);
.map(this::createGroup)
.ifPresent(root::addChild);
return root;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AutomaticKeywordGroupTest {
class AutomaticKeywordGroupTest {

@Test
public void createSubgroupsForTwoKeywords() throws Exception {
void createSubgroupsForTwoKeywords() throws Exception {
AutomaticKeywordGroup keywordsGroup = new AutomaticKeywordGroup("Keywords", GroupHierarchyType.INDEPENDENT, StandardField.KEYWORDS, ',', '>');
BibEntry entry = new BibEntry().withField(StandardField.KEYWORDS, "A, B");

Expand All @@ -22,4 +22,15 @@ public void createSubgroupsForTwoKeywords() throws Exception {
expected.add(GroupTreeNode.fromGroup(new WordKeywordGroup("B", GroupHierarchyType.INCLUDING, StandardField.KEYWORDS, "B", true, ',', true)));
assertEquals(expected, keywordsGroup.createSubgroups(entry));
}

@Test
void createSubgroupsIgnoresEmptyKeyword() throws Exception {
AutomaticKeywordGroup keywordsGroup = new AutomaticKeywordGroup("Keywords", GroupHierarchyType.INDEPENDENT, StandardField.KEYWORDS, ',', '>');
BibEntry entry = new BibEntry().withField(StandardField.KEYWORDS, "A, ,B");

Set<GroupTreeNode> expected = new HashSet<>();
expected.add(GroupTreeNode.fromGroup(new WordKeywordGroup("A", GroupHierarchyType.INCLUDING, StandardField.KEYWORDS, "A", true, ',', true)));
expected.add(GroupTreeNode.fromGroup(new WordKeywordGroup("B", GroupHierarchyType.INCLUDING, StandardField.KEYWORDS, "B", true, ',', true)));
assertEquals(expected, keywordsGroup.createSubgroups(entry));
}
}

0 comments on commit 96037df

Please sign in to comment.