Skip to content
This repository was archived by the owner on Oct 26, 2020. It is now read-only.

Commit f10c4ba

Browse files
author
LinuxMage
committed
Makes "cw" and "bw" act more like vim.
"cw" and "bw" now behave more like vim in very specific conditions. "cw" and "bw" should now work as they do in vim when the cursor is on the start of a paragraph before these commands are implemented.
1 parent 59641e2 commit f10c4ba

File tree

1 file changed

+63
-11
lines changed

1 file changed

+63
-11
lines changed

src/vibreoffice.vbs

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -998,11 +998,11 @@ Function ProcessMovementKey(keyChar, Optional bExpand, Optional keyModifiers)
998998

999999
' For the case when the user enters "w" or "dw":
10001000
Else
1001-
' For "w", using gotoNextWord would mean that the cursor would not
1002-
' be moved to the next word when it involved moving down a line and
1003-
' that line happened to begin with whitespace. It would also mean
1004-
' that the cursor would not skip over lines that only contain
1005-
' whitespace.
1001+
' Note: For "w", using gotoNextWord would mean that the cursor
1002+
' would not be moved to the next word when it involved moving down
1003+
' a line and that line happened to begin with whitespace. It would
1004+
' also mean that the cursor would not skip over lines that only
1005+
' contain whitespace.
10061006

10071007
If NOT (getSpecial() = "d" And oTextCursor.isEndOfParagraph()) Then
10081008
' Move cursor to right in case cursor is already at the start
@@ -1029,16 +1029,43 @@ Function ProcessMovementKey(keyChar, Optional bExpand, Optional keyModifiers)
10291029
ElseIf keyChar = "b" or keyChar = "B" Then
10301030
' When the user enters "b", "cb", or "db":
10311031

1032-
' The function gotoPreviousWord causes a lot of problems when trying
1033-
' to emulate vim behavior. The following method doesn't have to
1032+
' Note: The function gotoPreviousWord causes a lot of problems when
1033+
' trying to emulate vim behavior. The following method doesn't have to
10341034
' account for as many special cases.
10351035

1036-
' Moves the cursor to the start of the previous word or until an empty
1036+
' "b": Moves the cursor to the start of the previous word or until an empty
10371037
' line is reached.
10381038

1039-
' Move cursor to left in case cursor is already at the start
1040-
' of a word or on on an empty line.
1041-
oTextCursor.goLeft(1, bExpand)
1039+
' "db": Does same thing as "b" only it deletes everything between the
1040+
' orginal cursor position and the new cursor position. The exception to
1041+
' this is that if the original cursor position was at the start of a
1042+
' paragraph and the new cursor position is on a separate paragraph with
1043+
' at least two words then don't delete the new line char to the "left"
1044+
' of the original paragraph.
1045+
1046+
' "dc": Does the same as "db" only the new line char described in "db"
1047+
' above is never deleted.
1048+
1049+
1050+
' This variable is used to tell whether or not we need to make a
1051+
' distinction between "b", "cb", and "db".
1052+
dim dc_db as boolean
1053+
1054+
' Move cursor to left in case cursor is already at the start of a word
1055+
' or on on an empty line. If cursor can move left and user enterd "dc"
1056+
' or "db" and the cursor was originally on the start of a paragraph
1057+
' then set dc_db to true and unselect the new line character separating
1058+
' the paragraphs. If cursor can't move left then there is no line above
1059+
' the current one and no need to make a distinction between "b", "cb",
1060+
' and "db".
1061+
dc_db = False
1062+
If oTextCursor.isStartOfParagraph() And oTextCursor.goLeft(1, bExpand) Then
1063+
If getSpecial() = "c" Or getSpecial() = "d" Then
1064+
dc_db = True
1065+
' If all conditions above are met then unselect the \n char.
1066+
oTextCursor.collapseToStart()
1067+
End If
1068+
End If
10421069

10431070
' Stop looping when the cursor reaches the start of a word, an empty
10441071
' line, or cannot be moved further (reaches start of file).
@@ -1048,6 +1075,30 @@ Function ProcessMovementKey(keyChar, Optional bExpand, Optional keyModifiers)
10481075
Exit Do
10491076
End If
10501077
Loop
1078+
1079+
If dc_db Then
1080+
' Make a clone of oTextCursor called oTextCursor2 and use it to
1081+
' check if there are at least two words in the "new" paragraph.
1082+
' If there are <2 words then the loop will stop when the cursor
1083+
' cursor reaches the start of a paragraph. If there >=2 words then
1084+
' then the loop will stop when the cursor reaches the end of a word.
1085+
dim oTextCursor2
1086+
oTextCursor2 = getCursor().getText.createTextCursorByRange(oTextCursor)
1087+
Do Until oTextCursor2.isEndOfWord() Or oTextCursor2.isStartOfParagraph()
1088+
oTextCursor2.goLeft(1, bExpand)
1089+
Loop
1090+
' If there are less than 2 words on the "new" paragraph then set
1091+
' oTextCursor to oTextCursor 2. This is because vim's behavior is
1092+
' to clear the "new" paragraph under these conditions.
1093+
If oTextCursor2.isStartOfParagraph() Then
1094+
oTextCursor = oTextCursor2
1095+
oTextCursor.gotoRange(oTextCursor.getStart(), bExpand)
1096+
' If user entered "db" then reselect the \n char from before.
1097+
If getSpecial() = "d" Then
1098+
oTextCursor.goRight(1, bExpand)
1099+
End If
1100+
End If
1101+
End If
10511102
ElseIf keyChar = "e" Then
10521103
' When the user enters "e", "ce", or "de":
10531104

@@ -1058,6 +1109,7 @@ Function ProcessMovementKey(keyChar, Optional bExpand, Optional keyModifiers)
10581109
' Moves the cursor to the end of the next word or end of file if there
10591110
' are no more words.
10601111

1112+
10611113
' Move cursor to right in case cursor is already at the end of a word.
10621114
oTextCursor.goRight(1, bExpand)
10631115

0 commit comments

Comments
 (0)