Show More
@@ -181,30 +181,45 b' AUTO_MATCH_BINDINGS = [' | |||||
181 | ] |
|
181 | ] | |
182 |
|
182 | |||
183 | AUTO_SUGGEST_BINDINGS = [ |
|
183 | AUTO_SUGGEST_BINDINGS = [ | |
|
184 | # there are two reasons for re-defining bindings defined upstream: | |||
|
185 | # 1) prompt-toolkit does not execute autosuggestion bindings in vi mode, | |||
|
186 | # 2) prompt-toolkit checks if we are at the end of text, not end of line | |||
|
187 | # hence it does not work in multi-line mode of navigable provider | |||
184 | Binding( |
|
188 | Binding( | |
185 | auto_suggest.accept_in_vi_insert_mode, |
|
189 | auto_suggest.accept_in_vi_insert_mode, | |
186 | ["end"], |
|
190 | ["end"], | |
187 |
"default_buffer_focused & |
|
191 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |
188 | ), |
|
192 | ), | |
189 | Binding( |
|
193 | Binding( | |
190 | auto_suggest.accept_in_vi_insert_mode, |
|
194 | auto_suggest.accept_in_vi_insert_mode, | |
191 | ["c-e"], |
|
195 | ["c-e"], | |
192 |
" |
|
196 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |
|
197 | ), | |||
|
198 | Binding( | |||
|
199 | auto_suggest.accept, | |||
|
200 | ["c-f"], | |||
|
201 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |||
|
202 | ), | |||
|
203 | Binding( | |||
|
204 | auto_suggest.accept, | |||
|
205 | ["right"], | |||
|
206 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |||
193 | ), |
|
207 | ), | |
194 | Binding(auto_suggest.accept, ["c-f"], "vi_insert_mode & default_buffer_focused"), |
|
|||
195 | Binding( |
|
208 | Binding( | |
196 | auto_suggest.accept_word, |
|
209 | auto_suggest.accept_word, | |
197 | ["escape", "f"], |
|
210 | ["escape", "f"], | |
198 |
" |
|
211 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |
199 | ), |
|
212 | ), | |
200 | Binding( |
|
213 | Binding( | |
201 | auto_suggest.accept_token, |
|
214 | auto_suggest.accept_token, | |
202 | ["c-right"], |
|
215 | ["c-right"], | |
203 | "has_suggestion & default_buffer_focused", |
|
216 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |
204 | ), |
|
217 | ), | |
205 | Binding( |
|
218 | Binding( | |
206 | auto_suggest.discard, |
|
219 | auto_suggest.discard, | |
207 | ["escape"], |
|
220 | ["escape"], | |
|
221 | # note this one is using `emacs_insert_mode`, not `emacs_like_insert_mode` | |||
|
222 | # as in `vi_insert_mode` we do not want `escape` to be shadowed (ever). | |||
208 | "has_suggestion & default_buffer_focused & emacs_insert_mode", |
|
223 | "has_suggestion & default_buffer_focused & emacs_insert_mode", | |
209 | ), |
|
224 | ), | |
210 | Binding( |
|
225 | Binding( | |
@@ -236,22 +251,22 b' AUTO_SUGGEST_BINDINGS = [' | |||||
236 | Binding( |
|
251 | Binding( | |
237 | auto_suggest.accept_character, |
|
252 | auto_suggest.accept_character, | |
238 | ["escape", "right"], |
|
253 | ["escape", "right"], | |
239 | "has_suggestion & default_buffer_focused", |
|
254 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |
240 | ), |
|
255 | ), | |
241 | Binding( |
|
256 | Binding( | |
242 | auto_suggest.accept_and_move_cursor_left, |
|
257 | auto_suggest.accept_and_move_cursor_left, | |
243 | ["c-left"], |
|
258 | ["c-left"], | |
244 | "has_suggestion & default_buffer_focused", |
|
259 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |
245 | ), |
|
260 | ), | |
246 | Binding( |
|
261 | Binding( | |
247 | auto_suggest.accept_and_keep_cursor, |
|
262 | auto_suggest.accept_and_keep_cursor, | |
248 | ["c-down"], |
|
263 | ["c-down"], | |
249 | "has_suggestion & default_buffer_focused", |
|
264 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |
250 | ), |
|
265 | ), | |
251 | Binding( |
|
266 | Binding( | |
252 | auto_suggest.backspace_and_resume_hint, |
|
267 | auto_suggest.backspace_and_resume_hint, | |
253 | ["backspace"], |
|
268 | ["backspace"], | |
254 | "has_suggestion & default_buffer_focused", |
|
269 | "has_suggestion & default_buffer_focused & emacs_like_insert_mode", | |
255 | ), |
|
270 | ), | |
256 | ] |
|
271 | ] | |
257 |
|
272 |
@@ -178,9 +178,8 b' class NavigableAutoSuggestFromHistory(AutoSuggestFromHistory):' | |||||
178 | break |
|
178 | break | |
179 |
|
179 | |||
180 |
|
180 | |||
181 | # Needed for to accept autosuggestions in vi insert mode |
|
181 | def accept_or_jump_to_end(event: KeyPressEvent): | |
182 | def accept_in_vi_insert_mode(event: KeyPressEvent): |
|
182 | """Apply autosuggestion or jump to end of line.""" | |
183 | """Apply autosuggestion if at end of line.""" |
|
|||
184 | buffer = event.current_buffer |
|
183 | buffer = event.current_buffer | |
185 | d = buffer.document |
|
184 | d = buffer.document | |
186 | after_cursor = d.text[d.cursor_position :] |
|
185 | after_cursor = d.text[d.cursor_position :] | |
@@ -193,6 +192,15 b' def accept_in_vi_insert_mode(event: KeyPressEvent):' | |||||
193 | nc.end_of_line(event) |
|
192 | nc.end_of_line(event) | |
194 |
|
193 | |||
195 |
|
194 | |||
|
195 | def accept_in_vi_insert_mode(event: KeyPressEvent): | |||
|
196 | """Accept autosuggestion or jump to end of line. | |||
|
197 | ||||
|
198 | .. deprecated:: 8.12 | |||
|
199 | Use `accept_or_jump_to_end` instead. | |||
|
200 | """ | |||
|
201 | return accept_or_jump_to_end(event) | |||
|
202 | ||||
|
203 | ||||
196 | def accept(event: KeyPressEvent): |
|
204 | def accept(event: KeyPressEvent): | |
197 | """Accept autosuggestion""" |
|
205 | """Accept autosuggestion""" | |
198 | buffer = event.current_buffer |
|
206 | buffer = event.current_buffer |
@@ -181,10 +181,33 b' KEYBINDING_FILTERS = {' | |||||
181 | "vi_mode": vi_mode, |
|
181 | "vi_mode": vi_mode, | |
182 | "vi_insert_mode": vi_insert_mode, |
|
182 | "vi_insert_mode": vi_insert_mode, | |
183 | "emacs_insert_mode": emacs_insert_mode, |
|
183 | "emacs_insert_mode": emacs_insert_mode, | |
|
184 | # https://github.com/ipython/ipython/pull/12603 argued for inclusion of | |||
|
185 | # emacs key bindings with a configurable `emacs_bindings_in_vi_insert_mode` | |||
|
186 | # toggle; when the toggle is on user can access keybindigns like `ctrl + e` | |||
|
187 | # in vi insert mode. Because some of the emacs bindings involve `escape` | |||
|
188 | # followed by another key, e.g. `escape` followed by `f`, prompt-toolkit | |||
|
189 | # needs to wait to see if there will be another character typed in before | |||
|
190 | # executing pure `escape` keybinding; in vi insert mode `escape` switches to | |||
|
191 | # command mode which is common and performance critical action for vi users. | |||
|
192 | # To avoid the delay users employ a workaround: | |||
|
193 | # https://github.com/ipython/ipython/issues/13443#issuecomment-1032753703 | |||
|
194 | # which involves switching `emacs_bindings_in_vi_insert_mode` off. | |||
|
195 | # | |||
|
196 | # For the workaround to work: | |||
|
197 | # 1) end users need to toggle `emacs_bindings_in_vi_insert_mode` off | |||
|
198 | # 2) all keybindings which would involve `escape` need to respect that | |||
|
199 | # toggle by including either: | |||
|
200 | # - `vi_insert_mode & ebivim` for actions which have emacs keybindings | |||
|
201 | # predefined upstream in prompt-toolkit, or | |||
|
202 | # - `emacs_like_insert_mode` for actions which do not have existing | |||
|
203 | # emacs keybindings predefined upstream (or need overriding of the | |||
|
204 | # upstream bindings to modify behaviour), defined below. | |||
|
205 | "emacs_like_insert_mode": (vi_insert_mode & ebivim) | emacs_insert_mode, | |||
184 | "has_completions": has_completions, |
|
206 | "has_completions": has_completions, | |
185 | "insert_mode": vi_insert_mode | emacs_insert_mode, |
|
207 | "insert_mode": vi_insert_mode | emacs_insert_mode, | |
186 | "default_buffer_focused": default_buffer_focused, |
|
208 | "default_buffer_focused": default_buffer_focused, | |
187 | "search_buffer_focused": has_focus(SEARCH_BUFFER), |
|
209 | "search_buffer_focused": has_focus(SEARCH_BUFFER), | |
|
210 | # `ebivim` stands for emacs bindings in vi insert mode | |||
188 | "ebivim": ebivim, |
|
211 | "ebivim": ebivim, | |
189 | "supports_suspend": supports_suspend, |
|
212 | "supports_suspend": supports_suspend, | |
190 | "is_windows_os": is_windows_os, |
|
213 | "is_windows_os": is_windows_os, |
General Comments 0
You need to be logged in to leave comments.
Login now