summaryrefslogtreecommitdiffstats
path: root/src/prompt_toolkit/key_binding/bindings/vi.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 04:45:15 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 04:45:15 +0000
commit6dc655898df34ad424dfc467a8b276fdf31bd791 (patch)
tree0a3f3addbfc0b81e3850a628afe62ce830a8b0f3 /src/prompt_toolkit/key_binding/bindings/vi.py
parentReleasing progress-linux version 3.0.43-2~progress7.99u1. (diff)
downloadprompt-toolkit-6dc655898df34ad424dfc467a8b276fdf31bd791.tar.xz
prompt-toolkit-6dc655898df34ad424dfc467a8b276fdf31bd791.zip
Merging upstream version 3.0.46.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/prompt_toolkit/key_binding/bindings/vi.py')
-rw-r--r--src/prompt_toolkit/key_binding/bindings/vi.py51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/prompt_toolkit/key_binding/bindings/vi.py b/src/prompt_toolkit/key_binding/bindings/vi.py
index 5cc74b4..d68a31f 100644
--- a/src/prompt_toolkit/key_binding/bindings/vi.py
+++ b/src/prompt_toolkit/key_binding/bindings/vi.py
@@ -371,6 +371,35 @@ def create_operator_decorator(
return operator_decorator
+@Condition
+def is_returnable() -> bool:
+ return get_app().current_buffer.is_returnable
+
+
+@Condition
+def in_block_selection() -> bool:
+ buff = get_app().current_buffer
+ return bool(
+ buff.selection_state and buff.selection_state.type == SelectionType.BLOCK
+ )
+
+
+@Condition
+def digraph_symbol_1_given() -> bool:
+ return get_app().vi_state.digraph_symbol1 is not None
+
+
+@Condition
+def search_buffer_is_empty() -> bool:
+ "Returns True when the search buffer is empty."
+ return get_app().current_buffer.text == ""
+
+
+@Condition
+def tilde_operator() -> bool:
+ return get_app().vi_state.tilde_operator
+
+
def load_vi_bindings() -> KeyBindingsBase:
"""
Vi extensions.
@@ -410,7 +439,7 @@ def load_vi_bindings() -> KeyBindingsBase:
(("g", "~"), Always(), lambda string: string.swapcase()),
(
("~",),
- Condition(lambda: get_app().vi_state.tilde_operator),
+ tilde_operator,
lambda string: string.swapcase(),
),
]
@@ -528,10 +557,6 @@ def load_vi_bindings() -> KeyBindingsBase:
"""
event.current_buffer.cancel_completion()
- @Condition
- def is_returnable() -> bool:
- return get_app().current_buffer.is_returnable
-
# In navigation mode, pressing enter will always return the input.
handle("enter", filter=vi_navigation_mode & is_returnable)(
get_by_name("accept-line")
@@ -681,13 +706,6 @@ def load_vi_bindings() -> KeyBindingsBase:
)
)
- @Condition
- def in_block_selection() -> bool:
- buff = get_app().current_buffer
- return bool(
- buff.selection_state and buff.selection_state.type == SelectionType.BLOCK
- )
-
@handle("I", filter=in_block_selection & ~is_read_only)
def insert_in_block_selection(event: E, after: bool = False) -> None:
"""
@@ -2071,10 +2089,6 @@ def load_vi_bindings() -> KeyBindingsBase:
"""
event.app.vi_state.waiting_for_digraph = True
- @Condition
- def digraph_symbol_1_given() -> bool:
- return get_app().vi_state.digraph_symbol1 is not None
-
@handle(Keys.Any, filter=vi_digraph_mode & ~digraph_symbol_1_given)
def _digraph1(event: E) -> None:
"""
@@ -2180,11 +2194,6 @@ def load_vi_search_bindings() -> KeyBindingsBase:
handle = key_bindings.add
from . import search
- @Condition
- def search_buffer_is_empty() -> bool:
- "Returns True when the search buffer is empty."
- return get_app().current_buffer.text == ""
-
# Vi-style forward search.
handle(
"/",