|
4 | 4 | from __future__ import unicode_literals
|
5 | 5 | from prompt_toolkit.enums import IncrementalSearchDirection
|
6 | 6 | from prompt_toolkit.filters import HasFocus, Condition, HasSelection
|
7 |
| -from prompt_toolkit.key_binding.manager import KeyBindingManager as pt_KeyBindingManager |
| 7 | +from prompt_toolkit.key_binding.defaults import load_key_bindings, load_mouse_bindings |
| 8 | +from prompt_toolkit.key_binding.registry import MergedRegistry, ConditionalRegistry, Registry |
8 | 9 | from prompt_toolkit.key_binding.vi_state import InputMode
|
9 | 10 | from prompt_toolkit.keys import Keys
|
10 | 11 | from prompt_toolkit.selection import SelectionType
|
@@ -35,22 +36,26 @@ def get_search_state(cli):
|
35 | 36 | # Start from this KeyBindingManager from prompt_toolkit, to have basic
|
36 | 37 | # editing functionality for the command line. These key binding are
|
37 | 38 | # however only active when the following `enable_all` condition is met.
|
38 |
| - self.pt_key_bindings_manager = pt_KeyBindingManager( |
39 |
| - enable_all=(HasFocus(COMMAND) | HasFocus(PROMPT) | InScrollBuffer(pymux)) & ~HasPrefix(pymux), |
40 |
| - enable_auto_suggest_bindings=True, |
41 |
| - enable_search=False, # We have our own search bindings, that support multiple panes. |
42 |
| - enable_extra_page_navigation=True, |
43 |
| - get_search_state=get_search_state) |
44 |
| - |
45 |
| - self.registry = self.pt_key_bindings_manager.registry |
| 39 | + self.registry = MergedRegistry([ |
| 40 | + ConditionalRegistry( |
| 41 | + registry=load_key_bindings( |
| 42 | + enable_auto_suggest_bindings=True, |
| 43 | + enable_search=False, # We have our own search bindings, that support multiple panes. |
| 44 | + enable_extra_page_navigation=True, |
| 45 | + get_search_state=get_search_state), |
| 46 | + filter=(HasFocus(COMMAND) | HasFocus(PROMPT) | |
| 47 | + InScrollBuffer(pymux)) & ~HasPrefix(pymux), |
| 48 | + ), |
| 49 | + load_mouse_bindings(), |
| 50 | + self._load_builtins(), |
| 51 | + _load_search_bindings(pymux), |
| 52 | + ]) |
46 | 53 |
|
47 | 54 | self._prefix = (Keys.ControlB, )
|
48 | 55 | self._prefix_binding = None
|
49 | 56 |
|
50 | 57 | # Load initial bindings.
|
51 |
| - self._load_builtins() |
52 | 58 | self._load_prefix_binding()
|
53 |
| - _load_search_bindings(pymux, self.registry) |
54 | 59 |
|
55 | 60 | # Custom user configured key bindings.
|
56 | 61 | # { (needs_prefix, key) -> (command, handler) }
|
@@ -96,7 +101,7 @@ def _load_builtins(self):
|
96 | 101 | Fill the Registry with the hard coded key bindings.
|
97 | 102 | """
|
98 | 103 | pymux = self.pymux
|
99 |
| - registry = self.registry |
| 104 | + registry = Registry() |
100 | 105 |
|
101 | 106 | # Create filters.
|
102 | 107 | has_prefix = HasPrefix(pymux)
|
@@ -291,13 +296,14 @@ def __init__(self, handler, command, arguments):
|
291 | 296 | self.arguments = arguments
|
292 | 297 |
|
293 | 298 |
|
294 |
| -def _load_search_bindings(pymux, registry): |
| 299 | +def _load_search_bindings(pymux): |
295 | 300 | """
|
296 | 301 | Load the key bindings for searching. (Vi and Emacs)
|
297 | 302 |
|
298 | 303 | This is different from the ones of prompt_toolkit, because we have a
|
299 | 304 | individual search buffers for each pane.
|
300 | 305 | """
|
| 306 | + registry = Registry() |
301 | 307 | is_searching = InScrollBufferSearching(pymux)
|
302 | 308 | in_scroll_buffer_not_searching = InScrollBufferNotSearching(pymux)
|
303 | 309 |
|
@@ -396,3 +402,5 @@ def _(event):
|
396 | 402 | if not direction_changed:
|
397 | 403 | pane.scroll_buffer.apply_search(
|
398 | 404 | pane.search_state, include_current_position=False, count=event.arg)
|
| 405 | + |
| 406 | + return registry |
0 commit comments