Skip to content

Commit 1f5d7ab

Browse files
Fix crash when scrolling through cited by in Citation relations (#12877)
* 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 #12410 * fix: Apply OpenRewrite auto-fixes * fix: Revert unintended submodule changes to csl-styles and csl-locales * fix: Replaces WebView with scrollable Text/Label nodes --------- Co-authored-by: Subhramit Basu <[email protected]>
1 parent c552577 commit 1f5d7ab

File tree

2 files changed

+70
-6
lines changed

2 files changed

+70
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
107107
- We fixed an issue where JabRef interface would not properly refresh after a group removal. [#11487](https://github.com/JabRef/jabref/issues/11487)
108108
- We fixed an issue where valid DOI could not be imported if it had special characters like `<` or `>`. [#12434](https://github.com/JabRef/jabref/issues/12434)
109109
- We fixed an issue where the tooltip only displayed the first linked file when hovering. [#12470](https://github.com/JabRef/jabref/issues/12470)
110+
- 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)
110111
- We fixed an issue where some texts in the "Citation Information" tab and the "Preferences" dialog could not be translated. [#12883](https://github.com/JabRef/jabref/pull/12883)
111112
- We fixed an issue where file names were missing the citation key according to the filename format pattern after import. [#12556](https://github.com/JabRef/jabref/issues/12556)
112113
- We fixed an issue where downloading PDFs from URLs to empty entries resulted in meaningless filenames like "-.pdf". [#12917](https://github.com/JabRef/jabref/issues/12917)

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

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import javafx.scene.Node;
66
import javafx.scene.control.Label;
7+
import javafx.scene.control.ScrollPane;
78
import javafx.scene.layout.HBox;
89
import javafx.scene.layout.VBox;
910
import javafx.scene.text.Text;
@@ -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 = createLabel(authorsText);
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 = createLabel(titleText);
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 = createLabel(journalText);
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 = createSummary(summaryText);
5356
summary.getStyleClass().add("summary");
5457
entryContainer.getChildren().add(summary);
5558
});
@@ -74,4 +77,64 @@ private static IconTheme.JabRefIcons getIcon(EntryType type) {
7477
}
7578
return IconTheme.JabRefIcons.ARTICLE;
7679
}
80+
81+
/**
82+
* Checks if text contains right-to-left characters
83+
*
84+
* @param text Text to check
85+
* @return true if text contains RTL characters
86+
*/
87+
private static boolean isRTL(String text) {
88+
for (char c : text.toCharArray()) {
89+
if (Character.getDirectionality(c) == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
90+
Character.getDirectionality(c) == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC) {
91+
return true;
92+
}
93+
}
94+
return false;
95+
}
96+
97+
/**
98+
* Creates a text node for the summary with horizontal scrolling for RTL text,
99+
* avoiding JavaFX bug related to RTL text wrapping
100+
*
101+
* @param text The summary text content
102+
* @return Node with either:
103+
* - ScrollPane (for RTL text)
104+
* - TextFlowLimited (for LTR text)
105+
*/
106+
private static Node createSummary(String text) {
107+
if (isRTL(text)) {
108+
Text textNode = new Text(text);
109+
ScrollPane scrollPane = new ScrollPane(textNode);
110+
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
111+
scrollPane.setFitToHeight(true);
112+
return scrollPane;
113+
} else {
114+
return new TextFlowLimited(new Text(text));
115+
}
116+
}
117+
118+
/**
119+
* Creates a label with horizontal scrolling for RTL text,
120+
* avoiding JavaFX bug related to RTL text wrapping
121+
*
122+
* @param text The label text content
123+
* @return Node with either:
124+
* - ScrollPane (for RTL text)
125+
* - Wrapped Label (for LTR text)
126+
*/
127+
private static Node createLabel(String text) {
128+
if (isRTL(text)) {
129+
Label label = new Label(text);
130+
ScrollPane scrollPane = new ScrollPane(label);
131+
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
132+
scrollPane.setFitToHeight(true);
133+
return scrollPane;
134+
} else {
135+
Label label = new Label(text);
136+
label.setWrapText(true);
137+
return label;
138+
}
139+
}
77140
}

0 commit comments

Comments
 (0)