|
17 | 17 | from prompt_toolkit.filters import Condition, Always |
18 | 18 | from prompt_toolkit.history import FileHistory, InMemoryHistory |
19 | 19 | from prompt_toolkit.interface import CommandLineInterface, Application, AcceptAction |
20 | | -from prompt_toolkit.key_binding.manager import KeyBindingManager |
| 20 | +from prompt_toolkit.key_binding.defaults import load_key_bindings_for_prompt, load_mouse_bindings |
21 | 21 | from prompt_toolkit.key_binding.vi_state import InputMode |
| 22 | +from prompt_toolkit.key_binding.registry import MergedRegistry, ConditionalRegistry |
22 | 23 | from prompt_toolkit.layout.lexers import PygmentsLexer |
23 | 24 | from prompt_toolkit.shortcuts import create_output |
24 | 25 | from prompt_toolkit.styles import DynamicStyle |
@@ -226,22 +227,25 @@ def __init__(self, |
226 | 227 | # Code signatures. (This is set asynchronously after a timeout.) |
227 | 228 | self.signatures = [] |
228 | 229 |
|
229 | | - # Use a KeyBindingManager for loading the key bindings. |
230 | | - self.key_bindings_manager = KeyBindingManager( |
231 | | - enable_abort_and_exit_bindings=True, |
232 | | - enable_search=True, |
233 | | - enable_vi_mode=Condition(lambda cli: self.vi_mode), |
234 | | - enable_open_in_editor=Condition(lambda cli: self.enable_open_in_editor), |
235 | | - enable_system_bindings=Condition(lambda cli: self.enable_system_bindings), |
236 | | - enable_auto_suggest_bindings=Condition(lambda cli: self.enable_auto_suggest), |
237 | | - |
238 | | - # Disable all default key bindings when the sidebar or the exit confirmation |
239 | | - # are shown. |
240 | | - enable_all=Condition(lambda cli: not (self.show_sidebar or self.show_exit_confirmation))) |
241 | | - |
242 | | - load_python_bindings(self.key_bindings_manager, self) |
243 | | - load_sidebar_bindings(self.key_bindings_manager, self) |
244 | | - load_confirm_exit_bindings(self.key_bindings_manager, self) |
| 230 | + # Create a Registry for the key bindings. |
| 231 | + self.key_bindings_registry = MergedRegistry([ |
| 232 | + ConditionalRegistry( |
| 233 | + registry=load_key_bindings_for_prompt( |
| 234 | + enable_abort_and_exit_bindings=True, |
| 235 | + enable_search=True, |
| 236 | + enable_open_in_editor=Condition(lambda cli: self.enable_open_in_editor), |
| 237 | + enable_system_bindings=Condition(lambda cli: self.enable_system_bindings), |
| 238 | + enable_auto_suggest_bindings=Condition(lambda cli: self.enable_auto_suggest)), |
| 239 | + |
| 240 | + # Disable all default key bindings when the sidebar or the exit confirmation |
| 241 | + # are shown. |
| 242 | + filter=Condition(lambda cli: not (self.show_sidebar or self.show_exit_confirmation)) |
| 243 | + ), |
| 244 | + load_mouse_bindings(), |
| 245 | + load_python_bindings(self), |
| 246 | + load_sidebar_bindings(self), |
| 247 | + load_confirm_exit_bindings(self), |
| 248 | + ]) |
245 | 249 |
|
246 | 250 | # Boolean indicating whether we have a signatures thread running. |
247 | 251 | # (Never run more than one at the same time.) |
@@ -276,10 +280,6 @@ def get_compiler_flags(self): |
276 | 280 |
|
277 | 281 | return flags |
278 | 282 |
|
279 | | - @property |
280 | | - def key_bindings_registry(self): |
281 | | - return self.key_bindings_manager.registry |
282 | | - |
283 | 283 | @property |
284 | 284 | def add_key_binding(self): |
285 | 285 | """ |
@@ -505,7 +505,6 @@ def create_application(self): |
505 | 505 | return Application( |
506 | 506 | layout=create_layout( |
507 | 507 | self, |
508 | | - self.key_bindings_manager, |
509 | 508 | lexer=self._lexer, |
510 | 509 | input_buffer_height=self._input_buffer_height, |
511 | 510 | extra_buffer_processors=self._extra_buffer_processors, |
@@ -635,7 +634,6 @@ def run(): |
635 | 634 | cli.eventloop.run_in_executor(run) |
636 | 635 |
|
637 | 636 | def on_reset(self, cli): |
638 | | - self.key_bindings_manager.reset(cli) |
639 | 637 | self.signatures = [] |
640 | 638 |
|
641 | 639 | def enter_history(self, cli): |
|
0 commit comments