Add select/delete inner/a block
This commit is contained in:
parent
c660320c28
commit
7dd9fbe631
|
@ -10,8 +10,9 @@ vibreoffice currently supports:
|
||||||
- Movement keys: `hjkl`, `w`, `W`, `b`, `B`, `e`, `$`, `^`, `{}`, `()`, `C-d`, `C-u`
|
- Movement keys: `hjkl`, `w`, `W`, `b`, `B`, `e`, `$`, `^`, `{}`, `()`, `C-d`, `C-u`
|
||||||
- Search movement: `f`, `F`, `t`, `T`
|
- Search movement: `f`, `F`, `t`, `T`
|
||||||
- Number modifiers: e.g. `5w`, `4fa`
|
- Number modifiers: e.g. `5w`, `4fa`
|
||||||
- Deletion: `x`, `d`, `c`, `C`, `D`, `dd`, `cc`
|
- Deletion: `x`, `d`, `c`, `D`, `C`, `dd`, `cc`
|
||||||
- Plus movement and number modifiers: e.g. `dw`, `c$`, `5dd`, `c3j`, `2dfe`
|
- Plus movement and number modifiers: e.g. `5dw`, `c3j`, `2dfe`
|
||||||
|
- Delete a/inner block: e.g. `di(`, `da{`, `ci[`, `ci"`, `ca'`, `dit`
|
||||||
- More to come!
|
- More to come!
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
|
@ -521,7 +521,7 @@ Function ProcessMovementModifierKey(keyChar)
|
||||||
|
|
||||||
bMatched = True
|
bMatched = True
|
||||||
Select Case keyChar
|
Select Case keyChar
|
||||||
Case "f", "t", "F", "T":
|
Case "f", "t", "F", "T", "i", "a":
|
||||||
setMovementModifier(keyChar)
|
setMovementModifier(keyChar)
|
||||||
Case Else:
|
Case Else:
|
||||||
bMatched = False
|
bMatched = False
|
||||||
|
@ -531,12 +531,12 @@ Function ProcessMovementModifierKey(keyChar)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
' Returns the resulting TextCursor
|
|
||||||
Function ProcessSearchKey(oTextCursor, searchType, keyChar, bExpand)
|
Function ProcessSearchKey(oTextCursor, searchType, keyChar, bExpand)
|
||||||
'-----------
|
'-----------
|
||||||
' Searching
|
' Searching
|
||||||
'-----------
|
'-----------
|
||||||
dim oSearchDesc, oFoundRange, bIsBackwards, oStartRange
|
dim bMatched, oSearchDesc, oFoundRange, bIsBackwards, oStartRange
|
||||||
|
bMatched = True
|
||||||
bIsBackwards = (searchType = "F" Or searchType = "T")
|
bIsBackwards = (searchType = "F" Or searchType = "T")
|
||||||
|
|
||||||
If Not bIsBackwards Then
|
If Not bIsBackwards Then
|
||||||
|
@ -583,26 +583,79 @@ Function ProcessSearchKey(oTextCursor, searchType, keyChar, bExpand)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
' Prevent infinite if unable to find, but shouldn't ever happen (?)
|
' Prevent infinite if unable to find, but shouldn't ever happen (?)
|
||||||
If Not bSearching Then Exit Do
|
If Not bSearching Then
|
||||||
|
bMatched = False
|
||||||
|
Exit Do
|
||||||
|
End If
|
||||||
Loop
|
Loop
|
||||||
|
|
||||||
If getMovementModifier() = "t" Then
|
If searchType = "t" Then
|
||||||
oTextCursor.goLeft(1, bExpand)
|
oTextCursor.goLeft(1, bExpand)
|
||||||
ElseIf getMovementModifier() = "T" Then
|
ElseIf searchType = "T" Then
|
||||||
oTextCursor.goRight(1, bExpand)
|
oTextCursor.goRight(1, bExpand)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
' Yet another special case:
|
Else
|
||||||
' In VISUAL mode, we want to select PAST the character
|
bMatched = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
' If matched, then we want to select PAST the character
|
||||||
|
' Else, this will counteract some weirdness. hack either way
|
||||||
If Not bIsBackwards And MODE = "VISUAL" Then
|
If Not bIsBackwards And MODE = "VISUAL" Then
|
||||||
oTextCursor.goRight(1, bExpand)
|
oTextCursor.goRight(1, bExpand)
|
||||||
End If
|
End If
|
||||||
Else
|
|
||||||
' Pass?
|
ProcessSearchKey = bMatched
|
||||||
End If
|
|
||||||
|
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
Function ProcessInnerKey(oTextCursor, movementModifier, keyChar, bExpand)
|
||||||
|
dim bMatched, searchType1, searchType2, search1, search2
|
||||||
|
|
||||||
|
' Setting searchType
|
||||||
|
If movementModifier = "i" Then
|
||||||
|
searchType1 = "T" : searchType2 = "t"
|
||||||
|
ElseIf movementModifier = "a" Then
|
||||||
|
searchType1 = "F" : searchType2 = "f"
|
||||||
|
Else ' Shouldn't happen
|
||||||
|
ProcessInnerKey = False
|
||||||
|
Exit Function
|
||||||
|
End If
|
||||||
|
|
||||||
|
Select Case keyChar
|
||||||
|
Case "(", ")", "{", "}", "[", "]", "t", "'", """":
|
||||||
|
Select Case keyChar
|
||||||
|
Case "(", ")":
|
||||||
|
search1 = "(" : search2 = ")"
|
||||||
|
Case "{", "}":
|
||||||
|
search1 = "{" : search2 = "}"
|
||||||
|
Case "[", "]":
|
||||||
|
search1 = "[" : search2 = "}"
|
||||||
|
Case "t":
|
||||||
|
search1 = ">" : search2 = "<"
|
||||||
|
Case "'":
|
||||||
|
search1 = "'" : search2 = "'"
|
||||||
|
Case """":
|
||||||
|
' Matches "smart" quotes, which is default in libreoffice
|
||||||
|
search1 = "“" : search2 = "”"
|
||||||
|
End Select
|
||||||
|
|
||||||
|
dim bMatched1, bMatched2
|
||||||
|
bMatched1 = ProcessSearchKey(oTextCursor, searchType1, search1, False)
|
||||||
|
bMatched2 = ProcessSearchKey(oTextCursor, searchType2, search2, True)
|
||||||
|
|
||||||
|
bMatched = (bMatched1 And bMatched2)
|
||||||
|
|
||||||
|
Case Else:
|
||||||
|
bMatched = False
|
||||||
|
|
||||||
|
End Select
|
||||||
|
|
||||||
|
ProcessInnerKey = bMatched
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
' -----------------------
|
' -----------------------
|
||||||
' Main Movement Function
|
' Main Movement Function
|
||||||
' -----------------------
|
' -----------------------
|
||||||
|
@ -641,20 +694,26 @@ Function ProcessMovementKey(keyChar, Optional bExpand, Optional keyModifiers)
|
||||||
' Movement matching
|
' Movement matching
|
||||||
' ------------------
|
' ------------------
|
||||||
|
|
||||||
|
' ---------------------------------
|
||||||
' Special Case: Modified movements
|
' Special Case: Modified movements
|
||||||
If getMovementModifier() <> "" Then
|
If getMovementModifier() <> "" Then
|
||||||
Select Case getMovementModifier()
|
Select Case getMovementModifier()
|
||||||
' ------------------
|
|
||||||
' f,F,t,T searching
|
' f,F,t,T searching
|
||||||
' ------------------
|
|
||||||
Case "f", "t", "F", "T":
|
Case "f", "t", "F", "T":
|
||||||
processSearchKey(oTextCursor, getMovementModifier(), keyChar, bExpand)
|
bMatched = ProcessSearchKey(oTextCursor, getMovementModifier(), keyChar, bExpand)
|
||||||
|
Case "i", "a":
|
||||||
|
bMatched = ProcessInnerKey(oTextCursor, getMovementModifier(), keyChar, bExpand)
|
||||||
|
|
||||||
Case Else:
|
Case Else:
|
||||||
bSetCursor = False
|
bSetCursor = False
|
||||||
bMatched = False
|
bMatched = False
|
||||||
End Select
|
End Select
|
||||||
|
|
||||||
|
If Not bMatched Then
|
||||||
|
bSetCursor = False
|
||||||
|
End If
|
||||||
|
' ---------------------------------
|
||||||
|
|
||||||
ElseIf keyChar = "l" Then
|
ElseIf keyChar = "l" Then
|
||||||
oTextCursor.goRight(1, bExpand)
|
oTextCursor.goRight(1, bExpand)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue