mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
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:
parent
8dac83a9a0
commit
279d0ec638
4 changed files with 41 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
23
news/auto-suggest-word-alias.rst
Normal file
23
news/auto-suggest-word-alias.rst
Normal 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>
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue