Skip to content

Commit 3e275cf

Browse files
committed
Fix intermittent crashing under Unix. Closes #25
Something goes wrong with the view cursor, when inserting RTF text after adding additional paragraph end characters to prevent styling changes so we have to fiddle around with it to prevent crashing.
1 parent b767d21 commit 3e275cf

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

build/source/org/zotero/integration/ooo/comp/Document.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public void setBibliographyStyle(int firstLineIndent, int bodyIndent, int lineSp
429429
// this takes less than half as many lines in py-appscript!
430430
}
431431

432-
XTextViewCursor getSelection() {
432+
public XTextViewCursor getSelection() {
433433
XTextViewCursorSupplier supplier = (XTextViewCursorSupplier) UnoRuntime.queryInterface(XTextViewCursorSupplier.class, controller);
434434
return supplier.getViewCursor();
435435
}

build/source/org/zotero/integration/ooo/comp/ReferenceMark.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public String getText() throws Exception {
149149

150150
public void setText(String textString, boolean isRich) throws Exception {
151151
boolean isBibliography = getCode().startsWith("BIBL");
152+
XTextCursor viewCursor = doc.getSelection();
152153

153154
if(isBibliography) {
154155
prepareMultiline();
@@ -169,6 +170,11 @@ public void setText(String textString, boolean isRich) throws Exception {
169170
text.insertControlCharacter(range, ControlCharacter.PARAGRAPH_BREAK, false);
170171
text.insertControlCharacter(range.getEnd(), ControlCharacter.PARAGRAPH_BREAK, false);
171172
cursor.collapseToStart();
173+
// LibreOffice crashes here if we don't move the viewCursor.
174+
// Affects Ubuntu and maybe MacOS.
175+
// Don't ask me why it crashes though.
176+
viewCursor.gotoRange((XTextRange) cursor, false);
177+
viewCursor.goLeft((short)1, false);
172178
moveCursorRight(cursor, previousLen);
173179
}
174180
}
@@ -248,6 +254,10 @@ public void setText(String textString, boolean isRich) throws Exception {
248254
if(str.equals("\n") || str.equals("\r\n")) {
249255
dupRange.setString("");
250256
}
257+
258+
// Restoring cursor position
259+
viewCursor.gotoRange(dupRange, false);
260+
viewCursor.collapseToEnd();
251261

252262
dupRange = text.createTextCursorByRange(range);
253263
dupRange.collapseToStart();
66 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)