##// END OF EJS Templates
Expose `auto_suggest.resume_hinting`, fix resume on backspace (#13994)...
Matthias Bussonnier -
r28199:a7d8defd merge
parent child Browse files
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(
@@ -274,6 +274,14 b' AUTO_SUGGEST_BINDINGS = ['
274 # no `has_suggestion` here to allow resuming if no suggestion
274 # no `has_suggestion` here to allow resuming if no suggestion
275 "default_buffer_focused & emacs_like_insert_mode",
275 "default_buffer_focused & emacs_like_insert_mode",
276 ),
276 ),
277 Binding(
278 auto_suggest.resume_hinting,
279 ["right"],
280 # For now this binding is inactive (the filter includes `never`).
281 # TODO: remove `never` if we reach a consensus in #13991
282 # TODO: use `emacs_like_insert_mode` once #13991 is in
283 "never & default_buffer_focused & ((vi_insert_mode & ebivim) | emacs_insert_mode)",
284 ),
277 ]
285 ]
278
286
279
287
@@ -261,14 +261,13 b' def _update_hint(buffer: Buffer):'
261
261
262 def backspace_and_resume_hint(event: KeyPressEvent):
262 def backspace_and_resume_hint(event: KeyPressEvent):
263 """Resume autosuggestions after deleting last character"""
263 """Resume autosuggestions after deleting last character"""
264 current_buffer = event.current_buffer
264 nc.backward_delete_char(event)
265 _update_hint(event.current_buffer)
265
266
266 def resume_hinting(buffer: Buffer):
267 _update_hint(buffer)
268 current_buffer.on_text_changed.remove_handler(resume_hinting)
269
267
270 current_buffer.on_text_changed.add_handler(resume_hinting)
268 def resume_hinting(event: KeyPressEvent):
271 nc.backward_delete_char(event)
269 """Resume autosuggestions"""
270 return _update_hint(event.current_buffer)
272
271
273
272
274 def up_and_update_hint(event: KeyPressEvent):
273 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