From 6dc655898df34ad424dfc467a8b276fdf31bd791 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 5 Jun 2024 06:45:15 +0200 Subject: Merging upstream version 3.0.46. Signed-off-by: Daniel Baumann --- src/prompt_toolkit/key_binding/bindings/vi.py | 51 ++++++++++++++++----------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'src/prompt_toolkit/key_binding/bindings/vi.py') 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( "/", -- cgit v1.2.3