Skip to content

Commit 279c072

Browse files
Fix crash when scrolling through cited by in Citation relations
Uses Webview instead of Label and TextFlowLimited when trying to display right to left text (like persian or arabic) in BibEntryView. This resolves the issue caused by a javafx bug that causes an exception when rendering wrapped RTL text. Fixes JabRef#12410
1 parent 798f1e7 commit 279c072

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
8888
- We fixed an issue where JabRef would not open if an invalid external journal abbreviation path was encountered. [#12776](https://github.com/JabRef/jabref/issues/12776)
8989
- We fixed a bug where LaTeX commands were not removed from filenames generated using the `[bibtexkey] - [fulltitle]` pattern. [#12188](https://github.com/JabRef/jabref/issues/12188)
9090
- We fixed an issue where JabRef interface would not properly refresh after a group removal. [#11487](https://github.com/JabRef/jabref/issues/11487)
91+
- We fixed an issue where JabRef would crash when trying to display an entry in the Citation Relations tab that had right to left text. [#12410](https://github.com/JabRef/jabref/issues/12410)
9192

9293
### Removed
9394

src/main/java/org/jabref/gui/entryeditor/citationrelationtab/BibEntryView.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javafx.scene.layout.HBox;
88
import javafx.scene.layout.VBox;
99
import javafx.scene.text.Text;
10+
import javafx.scene.web.WebView;
1011

1112
import org.jabref.gui.icon.IconTheme;
1213
import org.jabref.gui.util.TextFlowLimited;
@@ -32,24 +33,26 @@ public class BibEntryView {
3233
public static Node getEntryNode(BibEntry entry) {
3334
Node entryType = getIcon(entry.getType()).getGraphicNode();
3435
entryType.getStyleClass().add("type");
35-
Label authors = new Label(entry.getFieldOrAliasLatexFree(StandardField.AUTHOR).orElse(""));
36+
String authorsText = entry.getFieldOrAliasLatexFree(StandardField.AUTHOR).orElse("");
37+
Node authors = createTextNode(authorsText, "authors");
3638
authors.getStyleClass().add("authors");
37-
authors.setWrapText(true);
38-
Label title = new Label(entry.getFieldOrAliasLatexFree(StandardField.TITLE).orElse(""));
39+
String titleText = entry.getFieldOrAliasLatexFree(StandardField.TITLE).orElse("");
40+
Node title = createTextNode(titleText, "title");
3941
title.getStyleClass().add("title");
40-
title.setWrapText(true);
4142
Label year = new Label(entry.getFieldOrAliasLatexFree(StandardField.YEAR).orElse(""));
4243
year.getStyleClass().add("year");
43-
Label journal = new Label(entry.getFieldOrAliasLatexFree(StandardField.JOURNAL).orElse(""));
44+
String journalText = entry.getFieldOrAliasLatexFree(StandardField.JOURNAL).orElse("");
45+
Node journal = createTextNode(journalText, "journal");
4446
journal.getStyleClass().add("journal");
4547

4648
VBox entryContainer = new VBox(
4749
new HBox(10, entryType, title),
4850
new HBox(5, year, journal),
4951
authors
5052
);
53+
5154
entry.getFieldOrAliasLatexFree(StandardField.ABSTRACT).ifPresent(summaryText -> {
52-
TextFlowLimited summary = new TextFlowLimited(new Text(summaryText));
55+
Node summary = createTextNode(summaryText, "summary");
5356
summary.getStyleClass().add("summary");
5457
entryContainer.getChildren().add(summary);
5558
});
@@ -74,4 +77,33 @@ private static IconTheme.JabRefIcons getIcon(EntryType type) {
7477
}
7578
return IconTheme.JabRefIcons.ARTICLE;
7679
}
80+
81+
private static boolean isRTL(String text) {
82+
for (char c : text.toCharArray()) {
83+
if (Character.getDirectionality(c) == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
84+
Character.getDirectionality(c) == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC ||
85+
Character.getDirectionality(c) == Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING ||
86+
Character.getDirectionality(c) == Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE) {
87+
return true;
88+
}
89+
}
90+
return false;
91+
}
92+
93+
private static Node createTextNode(String text, String fieldName) {
94+
if (isRTL(text)) {
95+
WebView webView = new WebView();
96+
webView.getEngine().loadContent(
97+
"<html><body dir='rtl'>" + text + "</body></html>"
98+
);
99+
webView.setPrefSize(200, 38);
100+
return webView;
101+
} else if (fieldName.equals("summary")) {
102+
return new TextFlowLimited(new Text(text));
103+
} else {
104+
Label label = new Label(text);
105+
label.setWrapText(true);
106+
return label;
107+
}
108+
}
77109
}

0 commit comments

Comments
 (0)