##// END OF EJS Templates
Discard auto-suggestion on `Esc`
krassowski -
Show More
@@ -343,8 +343,9 def create_ipython_shortcuts(shell, for_all_platforms: bool = False) -> KeyBindi
343 kb.add("c-right", filter=has_suggestion & has_focus(DEFAULT_BUFFER))(
343 kb.add("c-right", filter=has_suggestion & has_focus(DEFAULT_BUFFER))(
344 auto_suggest.accept_token
344 auto_suggest.accept_token
345 )
345 )
346 from functools import partial
346 kb.add("escape", filter=has_suggestion & has_focus(DEFAULT_BUFFER), eager=True)(
347
347 auto_suggest.discard
348 )
348 kb.add("up", filter=has_suggestion & has_focus(DEFAULT_BUFFER))(
349 kb.add("up", filter=has_suggestion & has_focus(DEFAULT_BUFFER))(
349 auto_suggest.swap_autosuggestion_up(shell.auto_suggest)
350 auto_suggest.swap_autosuggestion_up(shell.auto_suggest)
350 )
351 )
@@ -167,6 +167,12 def accept(event: KeyPressEvent):
167 nc.forward_char(event)
167 nc.forward_char(event)
168
168
169
169
170 def discard(event: KeyPressEvent):
171 """Discard autosuggestion"""
172 buffer = event.current_buffer
173 buffer.suggestion = None
174
175
170 def accept_word(event: KeyPressEvent):
176 def accept_word(event: KeyPressEvent):
171 """Fill partial autosuggestion by word"""
177 """Fill partial autosuggestion by word"""
172 buffer = event.current_buffer
178 buffer = event.current_buffer
@@ -6,6 +6,7 from IPython.terminal.shortcuts.auto_suggest import (
6 accept_character,
6 accept_character,
7 accept_word,
7 accept_word,
8 accept_and_keep_cursor,
8 accept_and_keep_cursor,
9 discard,
9 NavigableAutoSuggestFromHistory,
10 NavigableAutoSuggestFromHistory,
10 swap_autosuggestion_up,
11 swap_autosuggestion_up,
11 swap_autosuggestion_down,
12 swap_autosuggestion_down,
@@ -49,6 +50,22 def test_accept(text, suggestion, expected):
49
50
50
51
51 @pytest.mark.parametrize(
52 @pytest.mark.parametrize(
53 "text, suggestion",
54 [
55 ("", "def out(tag: str, n=50):"),
56 ("def ", "out(tag: str, n=50):"),
57 ],
58 )
59 def test_discard(text, suggestion):
60 event = make_event(text, len(text), suggestion)
61 buffer = event.current_buffer
62 buffer.insert_text = Mock()
63 discard(event)
64 assert not buffer.insert_text.called
65 assert buffer.suggestion is None
66
67
68 @pytest.mark.parametrize(
52 "text, cursor, suggestion, called",
69 "text, cursor, suggestion, called",
53 [
70 [
54 ("123456", 6, "123456789", True),
71 ("123456", 6, "123456789", True),
General Comments 0
You need to be logged in to leave comments. Login now