From 5d6cf029e70e933f8ceb56ea3871b995de257a1e Mon Sep 17 00:00:00 2001 From: Sean Yeh Date: Sat, 20 Dec 2014 17:11:53 -0600 Subject: [PATCH] add "r" --- README.md | 1 + src/vibreoffice.vbs | 38 ++++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ff0f39d..58eaa53 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ vibreoffice currently supports: - Movement keys: `hjkl`, `w`, `W`, `b`, `B`, `e`, `$`, `^`, `{}`, `()`, `C-d`, `C-u` - Search movement: `f`, `F`, `t`, `T` - Number modifiers: e.g. `5w`, `4fa` +- Replace: `r` - Deletion: `x`, `d`, `c`, `s`, `D`, `C`, `S`, `dd`, `cc` - Plus movement and number modifiers: e.g. `5dw`, `c3j`, `2dfe` - Delete a/inner block: e.g. `di(`, `da{`, `ci[`, `ci"`, `ca'`, `dit` diff --git a/src/vibreoffice.vbs b/src/vibreoffice.vbs index d78cffb..78038e3 100644 --- a/src/vibreoffice.vbs +++ b/src/vibreoffice.vbs @@ -105,6 +105,15 @@ Function samePos(oPos1, oPos2) samePos = oPos1.X() = oPos2.X() And oPos1.Y() = oPos2.Y() End FUnction +Function genString(sChar, iLen) + dim sResult, i + sResult = "" + For i = 1 To iLen + sResult = sResult & sChar + Next i + genString = sResult +End Function + ' ----------------------------------- ' Special Mode (for chained commands) @@ -240,6 +249,12 @@ function KeyHandler_KeyPressed(oEvent) as boolean ElseIf ProcessModeKey(oEvent) Then ' Pass + ' Replace Key + ElseIf getSpecial() = "r" And Not bIsModified Then + dim iLen + iLen = Len(getCursor().getString()) + getCursor().setString(genString(oEvent.KeyChar, iLen)) + ' Multiplier Key ElseIf ProcessNumberKey(oEvent) Then bIsMultiplier = True @@ -259,7 +274,6 @@ function KeyHandler_KeyPressed(oEvent) as boolean delaySpecialReset() - ' If bIsSpecial but nothing matched, return to normal mode ElseIf bIsSpecial Then gotoMode("NORMAL") @@ -398,10 +412,10 @@ Function ProcessNormalKey(keyChar, modifiers) ' -------------------- - ' 2. Check Delete Key + ' 2. Check Special/Delete Key ' -------------------- - ' There are no delete keys with modifier keys, so exit early + ' There are no special/delete keys with modifier keys, so exit early If modifiers > 1 Then ProcessNormalKey = False Exit Function @@ -412,21 +426,19 @@ Function ProcessNormalKey(keyChar, modifiers) iIterations = 1 End If For i = 1 To iIterations - dim bMatchedDelete + dim bMatchedSpecial - ' Delete Key - bMatchedDelete = ProcessDeleteKey(keyChar) + ' Special/Delete Key + bMatchedSpecial = ProcessSpecialKey(keyChar) - ' Selection Modifier Key ?? - - bMatched = bMatched or bMatchedDelete + bMatched = bMatched or bMatchedSpecial Next i ProcessNormalKey = bMatched End Function -Function ProcessDeleteKey(keyChar) +Function ProcessSpecialKey(keyChar) dim oTextCursor, bMatched, bIsSpecial bMatched = True bIsSpecial = getSpecial() <> "" @@ -481,6 +493,9 @@ Function ProcessDeleteKey(keyChar) End If End If + ' If is 'r' for replace + ElseIf keyChar = "r" Then + setSpecial("r") ' Otherwise, ignore if bIsSpecial ElseIf bIsSpecial Then @@ -530,7 +545,7 @@ Function ProcessDeleteKey(keyChar) bMatched = False End If - ProcessDeleteKey = bMatched + ProcessSpecialKey = bMatched End Function @@ -811,7 +826,6 @@ Sub initVibreoffice VIBREOFFICE_STARTED = True VIEW_CURSOR = thisComponent.getCurrentController.getViewCursor - resetMultiplier() gotoMode("NORMAL")