Show More
@@ -343,8 +343,9 b' def create_ipython_shortcuts(shell, for_all_platforms: bool = False) -> KeyBindi' | |||
|
343 | 343 | kb.add("c-right", filter=has_suggestion & has_focus(DEFAULT_BUFFER))( |
|
344 | 344 | auto_suggest.accept_token |
|
345 | 345 | ) |
|
346 | from functools import partial | |
|
347 | ||
|
346 | kb.add("escape", filter=has_suggestion & has_focus(DEFAULT_BUFFER), eager=True)( | |
|
347 | auto_suggest.discard | |
|
348 | ) | |
|
348 | 349 | kb.add("up", filter=has_suggestion & has_focus(DEFAULT_BUFFER))( |
|
349 | 350 | auto_suggest.swap_autosuggestion_up(shell.auto_suggest) |
|
350 | 351 | ) |
@@ -167,6 +167,12 b' def accept(event: KeyPressEvent):' | |||
|
167 | 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 | 176 | def accept_word(event: KeyPressEvent): |
|
171 | 177 | """Fill partial autosuggestion by word""" |
|
172 | 178 | buffer = event.current_buffer |
@@ -6,6 +6,7 b' from IPython.terminal.shortcuts.auto_suggest import (' | |||
|
6 | 6 | accept_character, |
|
7 | 7 | accept_word, |
|
8 | 8 | accept_and_keep_cursor, |
|
9 | discard, | |
|
9 | 10 | NavigableAutoSuggestFromHistory, |
|
10 | 11 | swap_autosuggestion_up, |
|
11 | 12 | swap_autosuggestion_down, |
@@ -49,6 +50,22 b' def test_accept(text, suggestion, expected):' | |||
|
49 | 50 | |
|
50 | 51 | |
|
51 | 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 | 69 | "text, cursor, suggestion, called", |
|
53 | 70 | [ |
|
54 | 71 | ("123456", 6, "123456789", True), |
General Comments 0
You need to be logged in to leave comments.
Login now