##// END OF EJS Templates
Expose `auto_suggest.resume_hinting`, fix resume on backspace
krassowski -
Show More
@@ -51,6 +51,7 b' from .pt_inputhooks import get_inputhook_name_and_func'
51 from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook
51 from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook
52 from .ptutils import IPythonPTCompleter, IPythonPTLexer
52 from .ptutils import IPythonPTCompleter, IPythonPTLexer
53 from .shortcuts import (
53 from .shortcuts import (
54 KEY_BINDINGS,
54 create_ipython_shortcuts,
55 create_ipython_shortcuts,
55 create_identifier,
56 create_identifier,
56 RuntimeBinding,
57 RuntimeBinding,
@@ -491,8 +492,8 b' class TerminalInteractiveShell(InteractiveShell):'
491 # for now we only allow adding shortcuts for commands which are already
492 # for now we only allow adding shortcuts for commands which are already
492 # registered; this is a security precaution.
493 # registered; this is a security precaution.
493 known_commands = {
494 known_commands = {
494 create_identifier(binding.handler): binding.handler
495 create_identifier(binding.command): binding.command
495 for binding in key_bindings.bindings
496 for binding in KEY_BINDINGS
496 }
497 }
497 shortcuts_to_skip = []
498 shortcuts_to_skip = []
498 shortcuts_to_add = []
499 shortcuts_to_add = []
@@ -513,11 +514,11 b' class TerminalInteractiveShell(InteractiveShell):'
513 )
514 )
514 matching = [
515 matching = [
515 binding
516 binding
516 for binding in key_bindings.bindings
517 for binding in KEY_BINDINGS
517 if (
518 if (
518 (old_filter is None or binding.filter == old_filter)
519 (old_filter is None or binding.filter == old_filter)
519 and (old_keys is None or [k for k in binding.keys] == old_keys)
520 and (old_keys is None or [k for k in binding.keys] == old_keys)
520 and create_identifier(binding.handler) == command_id
521 and create_identifier(binding.command) == command_id
521 )
522 )
522 ]
523 ]
523
524
@@ -542,7 +543,7 b' class TerminalInteractiveShell(InteractiveShell):'
542 }
543 }
543 if len(matching) == 0:
544 if len(matching) == 0:
544 raise ValueError(
545 raise ValueError(
545 f"No shortcuts matching {specification} found in {key_bindings.bindings}"
546 f"No shortcuts matching {specification} found in {KEY_BINDINGS}"
546 )
547 )
547 elif len(matching) > 1:
548 elif len(matching) > 1:
548 raise ValueError(
549 raise ValueError(
@@ -253,6 +253,14 b' AUTO_SUGGEST_BINDINGS = ['
253 ["backspace"],
253 ["backspace"],
254 "has_suggestion & default_buffer_focused",
254 "has_suggestion & default_buffer_focused",
255 ),
255 ),
256 Binding(
257 auto_suggest.resume_hinting,
258 ["right"],
259 # For now this binding is inactive (the filter includes `never`).
260 # TODO: remove `never` if we reach a consensus in #13991
261 # TODO: use `emacs_like_insert_mode` once #13991 is in
262 "never & default_buffer_focused & ((vi_insert_mode & ebivim) | emacs_insert_mode)",
263 ),
256 ]
264 ]
257
265
258
266
@@ -252,14 +252,13 b' def _update_hint(buffer: Buffer):'
252
252
253 def backspace_and_resume_hint(event: KeyPressEvent):
253 def backspace_and_resume_hint(event: KeyPressEvent):
254 """Resume autosuggestions after deleting last character"""
254 """Resume autosuggestions after deleting last character"""
255 current_buffer = event.current_buffer
255 nc.backward_delete_char(event)
256 _update_hint(event.current_buffer)
256
257
257 def resume_hinting(buffer: Buffer):
258 _update_hint(buffer)
259 current_buffer.on_text_changed.remove_handler(resume_hinting)
260
258
261 current_buffer.on_text_changed.add_handler(resume_hinting)
259 def resume_hinting(event: KeyPressEvent):
262 nc.backward_delete_char(event)
260 """Resume autosuggestions"""
261 return _update_hint(event.current_buffer)
263
262
264
263
265 def up_and_update_hint(event: KeyPressEvent):
264 def up_and_update_hint(event: KeyPressEvent):
@@ -17,6 +17,7 b' from prompt_toolkit.filters import Condition, emacs_insert_mode, has_completions'
17 from prompt_toolkit.filters import has_focus as has_focus_impl
17 from prompt_toolkit.filters import has_focus as has_focus_impl
18 from prompt_toolkit.filters import (
18 from prompt_toolkit.filters import (
19 Always,
19 Always,
20 Never,
20 has_selection,
21 has_selection,
21 has_suggestion,
22 has_suggestion,
22 vi_insert_mode,
23 vi_insert_mode,
@@ -174,6 +175,8 b' default_buffer_focused = has_focus(DEFAULT_BUFFER)'
174
175
175 KEYBINDING_FILTERS = {
176 KEYBINDING_FILTERS = {
176 "always": Always(),
177 "always": Always(),
178 # never is used for exposing commands which have no default keybindings
179 "never": Never(),
177 "has_line_below": has_line_below,
180 "has_line_below": has_line_below,
178 "has_line_above": has_line_above,
181 "has_line_above": has_line_above,
179 "has_selection": has_selection,
182 "has_selection": has_selection,
General Comments 0
You need to be logged in to leave comments. Login now