End-word additonal fixes.

End-word (e) will now behave more like it does in vim.
This commit is contained in:
LinuxMage 2015-11-22 00:47:54 -08:00
parent e2c23dd991
commit 3f3e097412
1 changed files with 26 additions and 16 deletions

View File

@ -978,23 +978,24 @@ Function ProcessMovementKey(keyChar, Optional bExpand, Optional keyModifiers)
' Using soley gotoNextWord would mean that the cursor would not be ' Using soley gotoNextWord would mean that the cursor would not be
' moved to the next word when it involved moving down a line and ' moved to the next word when it involved moving down a line and
' that line happened to begin with whitespace. It would also mean that ' that line happened to begin with whitespace. It would also mean that
' the cursor would not skip over lines that only contain whitespace. ' the cursor would not skip over lines that only contain whitespace.
oTextCursor.gotoNextWord(bExpand) oTextCursor.gotoNextWord(bExpand)
getCursor().gotoRange(oTextCursor.getStart(), False) getCursor().gotoRange(oTextCursor.getStart(), False)
' Stop looping when the cursor reaches the start of a word, an empty ' Stop looping when the cursor reaches the start of a word, an empty
' line, or cannot be moved further (reaches end of file). ' line, or cannot be moved further (reaches end of file).
Do Until oTextCursor.isStartOfWord() Or (getCursor().isAtStartOfLine() And getCursor().isAtEndOfLine()) Do Until oTextCursor.isStartOfWord() Or (getCursor().isAtStartOfLine() And getCursor().isAtEndOfLine())
' gotoNextWord returns false when it cannot further advance the ' gotoNextWord returns false when it cannot further advance the
' cursor. ' cursor.
If NOT oTextCursor.gotoNextWord(bExpand) Then If NOT oTextCursor.gotoNextWord(bExpand) Then
Exit Do Exit Do
End If End If
getCursor().gotoRange(oTextCursor.getStart(), False) getCursor().gotoRange(oTextCursor.getStart(), False)
Loop Loop
ElseIf keyChar = "b" or keyChar = "B" Then ElseIf keyChar = "b" or keyChar = "B" Then
' The function gotoPreviousWord causes a lot of problems. The ' The function gotoPreviousWord causes a lot of problems when trying
' following method doesn't have to account for as many special cases. ' to emulate vim behavior. The following method doesn't have to
' account for as many special cases.
' Move cursor to left in case cursor is already at the start of a word ' Move cursor to left in case cursor is already at the start of a word
' or is already on an empty line. ' or is already on an empty line.
@ -1013,17 +1014,26 @@ Function ProcessMovementKey(keyChar, Optional bExpand, Optional keyModifiers)
getCursor().goLeft(1, bExpand) getCursor().goLeft(1, bExpand)
Loop Loop
ElseIf keyChar = "e" Then ElseIf keyChar = "e" Then
If oTextCursor.isEndOfWord(bExpand) Then ' The function gotoNextWord causes a lot of problems when trying to
oTextCursor.gotoNextWord(bExpand) ' emulate vim behavior. The following method doesn't have to account
End If ' for as many special cases.
oTextCursor.gotoEndOfWord(bExpand)
' This is needed in case the current line starts with whitespace. ' Move cursor to right in case cursor is already at the end of a word
' This way it will go to the next line (if it exists). ' or is already on an empty line.
If NOT oTextCursor.isEndofWord(bExpand) Then oTextCursor.goRight(1, bExpand)
oTextCursor.gotoNextWord(bExpand) getCursor().goRight(1, bExpand)
oTextCursor.gotoEndofWord(bExpand)
End If ' Move cursor right to the end of next word or until it hits an empty
' line or until it can't move right anymore (reaches first line).
' gotoEndOfWord gets stuck sometimes so manually moving the cursor
' right is necessary in these cases.
Do Until oTextCursor.gotoEndOfWord(bExpand) Or (getCursor().isAtStartOfLine() And getCursor().isAtEndOfLine())
' If cursor can no longer move right then break loop
If NOT oTextCursor.goRight(1, bExpand) Then
Exit Do
End If
getCursor().goRight(1, bExpand)
Loop
ElseIf keyChar = ")" Then ElseIf keyChar = ")" Then
oTextCursor.gotoNextSentence(bExpand) oTextCursor.gotoNextSentence(bExpand)