mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
Accept single completion in VI MODE, add support for Ctrl+] for accepting a single completion
This commit is contained in:
parent
5f62cd8b4e
commit
aad6bb015c
2 changed files with 22 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
* Added `Ctrl+Right Arrow` support for accepting a single auto-completions in VI_MODE. It also add `Ctrl+Closing Square Bracket` support for accepting a single auto-completion so your hands may stay on the primary area of the keyboard.
|
||||
|
||||
**Changed:**
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Key bindings for prompt_toolkit xonsh shell."""
|
||||
|
||||
import re
|
||||
|
||||
from prompt_toolkit import search
|
||||
from prompt_toolkit.application.current import get_app
|
||||
from prompt_toolkit.enums import DEFAULT_BUFFER
|
||||
|
@ -10,10 +12,12 @@ from prompt_toolkit.filters import (
|
|||
IsMultiline,
|
||||
IsSearching,
|
||||
ViInsertMode,
|
||||
has_suggestion,
|
||||
)
|
||||
from prompt_toolkit.input import ansi_escape_sequences
|
||||
from prompt_toolkit.key_binding.bindings.named_commands import get_by_name
|
||||
from prompt_toolkit.key_binding.key_bindings import KeyBindings, KeyBindingsBase
|
||||
from prompt_toolkit.key_binding.key_processor import KeyPressEvent
|
||||
from prompt_toolkit.keys import Keys
|
||||
|
||||
from xonsh.aliases import xonsh_exit
|
||||
|
@ -428,6 +432,23 @@ def load_xonsh_bindings(ptk_bindings: KeyBindingsBase) -> KeyBindingsBase:
|
|||
|
||||
# Complete a single auto-suggestion word
|
||||
create_alias([Keys.ControlRight], ["escape", "f"])
|
||||
create_alias([Keys.ControlSquareClose], ["escape", "f"])
|
||||
|
||||
@handle(Keys.ControlRight, filter=has_suggestion)
|
||||
@handle(Keys.ControlSquareClose, filter=has_suggestion)
|
||||
def _fill(event: KeyPressEvent) -> None:
|
||||
"""
|
||||
Fill partial suggestion. This supports VI_MODE
|
||||
derived from:
|
||||
https://github.com/prompt-toolkit/python-prompt-toolkit/blob/465ab02854763fafc0099a2e38a56328c1cb0625/src/prompt_toolkit/key_binding/bindings/auto_suggest.py#L54
|
||||
"""
|
||||
|
||||
b = event.current_buffer
|
||||
suggestion = b.suggestion
|
||||
|
||||
if suggestion:
|
||||
t = re.split(r"([^\s/]+(?:\s+|/))", suggestion.text)
|
||||
b.insert_text(next(x for x in t if x))
|
||||
|
||||
# since macOS uses Control as reserved, then we use the alt/option key instead
|
||||
# which is mapped as the "escape" key
|
||||
|
|
Loading…
Add table
Reference in a new issue