Skip to content

Commit 8f68f40

Browse files
Implemented Vi ab,ib,aB,iB text objects.
1 parent 1be9ddd commit 8f68f40

File tree

1 file changed

+11
-5
lines changed
  • prompt_toolkit/key_binding/bindings

1 file changed

+11
-5
lines changed

prompt_toolkit/key_binding/bindings/vi.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,16 +1020,13 @@ def key_zero(event):
10201020
"""
10211021
return TextObject(event.current_buffer.document.get_start_of_line_position(after_whitespace=False))
10221022

1023-
def create_ci_ca_handles(ci_start, ci_end, inner):
1024-
# TODO: 'dab', 'dib', (brackets or block) 'daB', 'diB', Braces.
1023+
def create_ci_ca_handles(ci_start, ci_end, inner, key=None):
10251024
# TODO: 'dat', 'dit', (tags (like xml)
10261025
"""
10271026
Delete/Change string between this start and stop character. But keep these characters.
10281027
This implements all the ci", ci<, ci{, ci(, di", di<, ca", ca<, ... combinations.
10291028
"""
1030-
@text_object('ai'[inner], ci_start, no_move_handler=True)
1031-
@text_object('ai'[inner], ci_end, no_move_handler=True)
1032-
def _(event):
1029+
def handler(event):
10331030
if ci_start == ci_end:
10341031
# Quotes
10351032
start = event.current_buffer.document.find_backwards(ci_start, in_current_line=False)
@@ -1046,11 +1043,20 @@ def _(event):
10461043
# Nothing found.
10471044
return TextObject(0)
10481045

1046+
if key is None:
1047+
text_object('ai'[inner], ci_start, no_move_handler=True)(handler)
1048+
text_object('ai'[inner], ci_end, no_move_handler=True)(handler)
1049+
else:
1050+
text_object('ai'[inner], key, no_move_handler=True)(handler)
1051+
10491052
for inner in (False, True):
10501053
for ci_start, ci_end in [('"', '"'), ("'", "'"), ("`", "`"),
10511054
('[', ']'), ('<', '>'), ('{', '}'), ('(', ')')]:
10521055
create_ci_ca_handles(ci_start, ci_end, inner)
10531056

1057+
create_ci_ca_handles('(', ')', inner, 'b') # 'dab', 'dib'
1058+
create_ci_ca_handles('{', '}', inner, 'B') # 'daB', 'diB'
1059+
10541060
@text_object('{')
10551061
def _(event):
10561062
"""

0 commit comments

Comments
 (0)