Auto suggest word alias (#4401)

* ptk: key-bindings: Add CTRL-Right to auto-suggest a word

* news: Add auto-suggest-word-alias
This commit is contained in:
Daniel Shimon 2021-07-29 12:50:47 +03:00 committed by GitHub
parent 8dac83a9a0
commit 279d0ec638
Failed to generate hash of commit
4 changed files with 41 additions and 2 deletions

View file

@ -31,4 +31,6 @@ Xonsh comes pre-baked with a few keyboard shortcuts. The following is only avail
- Cut highlighted section
* - Ctrl-V *[Beta]*
- Paste clipboard contents
* - Ctrl-Right
- Complete a single auto-suggestion word

View file

@ -0,0 +1,23 @@
**Added:**
* Add ``CTRL-Right`` key binding to complete a single auto-suggestion word.
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -208,9 +208,14 @@ def wrap_selection(buffer, left, right=None):
buffer.selection_state = selection_state
def load_xonsh_bindings() -> KeyBindingsBase:
def load_xonsh_bindings(ptk_bindings: KeyBindingsBase) -> KeyBindingsBase:
"""
Load custom key bindings.
Parameters
----------
ptk_bindings :
The default prompt toolkit bindings. We need these to add aliases to them.
"""
key_bindings = KeyBindings()
handle = key_bindings.add
@ -389,4 +394,12 @@ def load_xonsh_bindings() -> KeyBindingsBase:
buff.cut_selection()
get_by_name("yank").call(event)
def create_alias(new_keys, original_keys):
bindings = ptk_bindings.get_bindings_for_keys(tuple(original_keys))
for original_binding in bindings:
handle(*new_keys, filter=original_binding.filter)(original_binding.handler)
# Complete a single auto-suggestion word
create_alias([Keys.ControlRight], ["escape", "f"])
return key_bindings

View file

@ -207,7 +207,8 @@ class PromptToolkitShell(BaseShell):
self.prompt_formatter = PTKPromptFormatter(self.prompter)
self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx, self)
self.key_bindings = load_xonsh_bindings()
ptk_bindings = self.prompter.app.key_bindings
self.key_bindings = load_xonsh_bindings(ptk_bindings)
self._overrides_deprecation_warning_shown = False
# Store original `_history_matches` in case we need to restore it