Skip to content

Commit 3394bc1

Browse files
Use 'prompt_toolkit.key_binding.defaults.load_key_bindings' instead of KeyBindingManager.
1 parent b29b524 commit 3394bc1

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

pymux/key_bindings.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from __future__ import unicode_literals
55
from prompt_toolkit.enums import IncrementalSearchDirection
66
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
89
from prompt_toolkit.key_binding.vi_state import InputMode
910
from prompt_toolkit.keys import Keys
1011
from prompt_toolkit.selection import SelectionType
@@ -35,22 +36,26 @@ def get_search_state(cli):
3536
# Start from this KeyBindingManager from prompt_toolkit, to have basic
3637
# editing functionality for the command line. These key binding are
3738
# 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+
])
4653

4754
self._prefix = (Keys.ControlB, )
4855
self._prefix_binding = None
4956

5057
# Load initial bindings.
51-
self._load_builtins()
5258
self._load_prefix_binding()
53-
_load_search_bindings(pymux, self.registry)
5459

5560
# Custom user configured key bindings.
5661
# { (needs_prefix, key) -> (command, handler) }
@@ -96,7 +101,7 @@ def _load_builtins(self):
96101
Fill the Registry with the hard coded key bindings.
97102
"""
98103
pymux = self.pymux
99-
registry = self.registry
104+
registry = Registry()
100105

101106
# Create filters.
102107
has_prefix = HasPrefix(pymux)
@@ -291,13 +296,14 @@ def __init__(self, handler, command, arguments):
291296
self.arguments = arguments
292297

293298

294-
def _load_search_bindings(pymux, registry):
299+
def _load_search_bindings(pymux):
295300
"""
296301
Load the key bindings for searching. (Vi and Emacs)
297302
298303
This is different from the ones of prompt_toolkit, because we have a
299304
individual search buffers for each pane.
300305
"""
306+
registry = Registry()
301307
is_searching = InScrollBufferSearching(pymux)
302308
in_scroll_buffer_not_searching = InScrollBufferNotSearching(pymux)
303309

@@ -396,3 +402,5 @@ def _(event):
396402
if not direction_changed:
397403
pane.scroll_buffer.apply_search(
398404
pane.search_state, include_current_position=False, count=event.arg)
405+
406+
return registry

0 commit comments

Comments
 (0)