Skip to content

Commit 96037df

Browse files
authored
Fix display bug for keyword groups with empty keywords (#5347)
Fix display bug for keyword groups with empty keywords
2 parents 631cec5 + dc4efcb commit 96037df

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
2525
- 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)
2626
- The group panel is now properly updated when switching between libraries (or when closing/opening one). [#3142](https://github.com/JabRef/jabref/issues/3142)
2727
- 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)
28+
- We fixed an issue where empty keywords lead to a strange display of automatic keyword groups. [#5333](https://github.com/JabRef/jabref/issues/5333)
2829
- 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)
2930
- We fixed an error mentioning "javafx.controls/com.sun.javafx.scene.control" that was thrown when interacting with the toolbar.
3031
- We fixed an error where a cleared search was restored after switching libraries. [#4846](https://github.com/JabRef/jabref/issues/4846)

src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.jabref.model.entry.Keyword;
1010
import org.jabref.model.entry.KeywordList;
1111
import org.jabref.model.entry.field.Field;
12+
import org.jabref.model.strings.StringUtil;
1213
import org.jabref.model.util.OptionalUtil;
1314

1415
public class AutomaticKeywordGroup extends AutomaticGroup {
@@ -62,11 +63,12 @@ public int hashCode() {
6263
@Override
6364
public Set<GroupTreeNode> createSubgroups(BibEntry entry) {
6465
Optional<KeywordList> keywordList = entry.getLatexFreeField(field)
65-
.map(fieldValue -> KeywordList.parse(fieldValue, keywordDelimiter));
66+
.map(fieldValue -> KeywordList.parse(fieldValue, keywordDelimiter));
6667
return OptionalUtil.toStream(keywordList)
67-
.flatMap(KeywordList::stream)
68-
.map(this::createGroup)
69-
.collect(Collectors.toSet());
68+
.flatMap(KeywordList::stream)
69+
.filter(keyword -> StringUtil.isNotBlank(keyword.get()))
70+
.map(this::createGroup)
71+
.collect(Collectors.toSet());
7072
}
7173

7274
private GroupTreeNode createGroup(Keyword keywordChain) {
@@ -80,8 +82,8 @@ private GroupTreeNode createGroup(Keyword keywordChain) {
8082
true);
8183
GroupTreeNode root = new GroupTreeNode(rootGroup);
8284
keywordChain.getChild()
83-
.map(this::createGroup)
84-
.ifPresent(root::addChild);
85+
.map(this::createGroup)
86+
.ifPresent(root::addChild);
8587
return root;
8688
}
8789
}

src/test/java/org/jabref/model/groups/AutomaticKeywordGroupTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

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

13-
public class AutomaticKeywordGroupTest {
13+
class AutomaticKeywordGroupTest {
1414

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

@@ -22,4 +22,15 @@ public void createSubgroupsForTwoKeywords() throws Exception {
2222
expected.add(GroupTreeNode.fromGroup(new WordKeywordGroup("B", GroupHierarchyType.INCLUDING, StandardField.KEYWORDS, "B", true, ',', true)));
2323
assertEquals(expected, keywordsGroup.createSubgroups(entry));
2424
}
25+
26+
@Test
27+
void createSubgroupsIgnoresEmptyKeyword() throws Exception {
28+
AutomaticKeywordGroup keywordsGroup = new AutomaticKeywordGroup("Keywords", GroupHierarchyType.INDEPENDENT, StandardField.KEYWORDS, ',', '>');
29+
BibEntry entry = new BibEntry().withField(StandardField.KEYWORDS, "A, ,B");
30+
31+
Set<GroupTreeNode> expected = new HashSet<>();
32+
expected.add(GroupTreeNode.fromGroup(new WordKeywordGroup("A", GroupHierarchyType.INCLUDING, StandardField.KEYWORDS, "A", true, ',', true)));
33+
expected.add(GroupTreeNode.fromGroup(new WordKeywordGroup("B", GroupHierarchyType.INCLUDING, StandardField.KEYWORDS, "B", true, ',', true)));
34+
assertEquals(expected, keywordsGroup.createSubgroups(entry));
35+
}
2536
}

0 commit comments

Comments
 (0)