Skip to content

Commit

Permalink
Fix intermittent crashing under Unix. Closes #25
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adomasven committed Apr 27, 2017
1 parent b767d21 commit 3e275cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/source/org/zotero/integration/ooo/comp/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public void setBibliographyStyle(int firstLineIndent, int bodyIndent, int lineSp
// this takes less than half as many lines in py-appscript!
}

XTextViewCursor getSelection() {
public XTextViewCursor getSelection() {
XTextViewCursorSupplier supplier = (XTextViewCursorSupplier) UnoRuntime.queryInterface(XTextViewCursorSupplier.class, controller);
return supplier.getViewCursor();
}
Expand Down
10 changes: 10 additions & 0 deletions build/source/org/zotero/integration/ooo/comp/ReferenceMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public String getText() throws Exception {

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

if(isBibliography) {
prepareMultiline();
Expand All @@ -169,6 +170,11 @@ public void setText(String textString, boolean isRich) throws Exception {
text.insertControlCharacter(range, ControlCharacter.PARAGRAPH_BREAK, false);
text.insertControlCharacter(range.getEnd(), ControlCharacter.PARAGRAPH_BREAK, false);
cursor.collapseToStart();
// LibreOffice crashes here if we don't move the viewCursor.
// Affects Ubuntu and maybe MacOS.
// Don't ask me why it crashes though.
viewCursor.gotoRange((XTextRange) cursor, false);
viewCursor.goLeft((short)1, false);
moveCursorRight(cursor, previousLen);
}
}
Expand Down Expand Up @@ -248,6 +254,10 @@ public void setText(String textString, boolean isRich) throws Exception {
if(str.equals("\n") || str.equals("\r\n")) {
dupRange.setString("");
}

// Restoring cursor position
viewCursor.gotoRange(dupRange, false);
viewCursor.collapseToEnd();

dupRange = text.createTextCursorByRange(range);
dupRange.collapseToStart();
Expand Down
Binary file modified install/Zotero_OpenOffice_Integration.oxt
Binary file not shown.

0 comments on commit 3e275cf

Please sign in to comment.