From f25a3bfff4fa60059269c8415987a3d9b894eb6e Mon Sep 17 00:00:00 2001 From: Sean Yeh Date: Fri, 24 Jul 2015 08:37:44 -0500 Subject: [PATCH] #21: Fix annotation insertion error --- src/vibreoffice.vbs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/vibreoffice.vbs b/src/vibreoffice.vbs index bc7ade8..d15618e 100644 --- a/src/vibreoffice.vbs +++ b/src/vibreoffice.vbs @@ -46,10 +46,15 @@ End Function Function getTextCursor dim oTextCursor + On Error Goto ErrorHandler oTextCursor = getCursor().getText.createTextCursorByRange(getCursor()) - ' oTextCursor.gotoRange(oTextCursor.getStart(), False) getTextCursor = oTextCursor + Exit Function + +ErrorHandler: + ' Text Cursor does not work in some instances, such as in Annotations + getTextCursor = Nothing End Function ' ----------------- @@ -251,12 +256,21 @@ End Sub ' Main Key Processing ' -------------------- function KeyHandler_KeyPressed(oEvent) as boolean + dim oTextCursor + ' Exit if plugin is not enabled If IsMissing(VIBREOFFICE_ENABLED) Or Not VIBREOFFICE_ENABLED Then KeyHandler_KeyPressed = False Exit Function End If + ' Exit if TextCursor does not work (as in Annotations) + oTextCursor = getTextCursor() + If oTextCursor Is Nothing Then + KeyHandler_KeyPressed = False + Exit Function + End If + dim bConsumeInput, bIsMultiplier, bIsModified, bIsSpecial bConsumeInput = True ' Block all inputs by default bIsMultiplier = False ' reset multiplier by default @@ -333,7 +347,9 @@ Function KeyHandler_KeyReleased(oEvent) As boolean ' Show terminal-like cursor oTextCursor = getTextCursor() - If oEvent.Modifiers = 2 Or oEvent.Modifiers = 8 And oEvent.KeyChar = "c" Then + If oTextCursor Is Nothing Then + ' Do nothing + ElseIf oEvent.Modifiers = 2 Or oEvent.Modifiers = 8 And oEvent.KeyChar = "c" Then ' Allow Ctrl+c for Copy, so don't change cursor ' Pass ElseIf MODE = "NORMAL" Then @@ -976,7 +992,12 @@ Sub initVibreoffice ' Show terminal cursor oTextCursor = getTextCursor() - cursorReset(oTextCursor) + + If oTextCursor Is Nothing Then + ' Do nothing + Else + cursorReset(oTextCursor) + End If sStartXKeyHandler() End Sub