diff options
author | Aldo Cortesi <aldo@corte.si> | 2017-06-14 10:01:07 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2017-06-14 10:01:07 +1200 |
commit | e8939b8b9fd53f49cc06f1f75c88ca9e63823b9e (patch) | |
tree | e1c4946bf2319872c80df0bfaca98f1455fe2266 | |
parent | 2108bfb10626a71ca8871e72328f8bcb9be85d3b (diff) | |
download | mitmproxy-e8939b8b9fd53f49cc06f1f75c88ca9e63823b9e.tar.gz mitmproxy-e8939b8b9fd53f49cc06f1f75c88ca9e63823b9e.tar.bz2 mitmproxy-e8939b8b9fd53f49cc06f1f75c88ca9e63823b9e.zip |
console: keybindings tweaks
- consistent sort order
- preserve help on edit
-rw-r--r-- | mitmproxy/tools/console/keybindings.py | 2 | ||||
-rw-r--r-- | mitmproxy/tools/console/keymap.py | 15 |
2 files changed, 10 insertions, 7 deletions
diff --git a/mitmproxy/tools/console/keybindings.py b/mitmproxy/tools/console/keybindings.py index cbde030a..45f5c33c 100644 --- a/mitmproxy/tools/console/keybindings.py +++ b/mitmproxy/tools/console/keybindings.py @@ -48,8 +48,8 @@ class KeyListWalker(urwid.ListWalker): def sig_modified(self, sender): self.bindings = list(self.master.keymap.list("all")) - self._modified() self.set_focus(min(self.index, len(self.bindings) - 1)) + self._modified() def get_edit_text(self): return self.focus_obj.get_edit_text() diff --git a/mitmproxy/tools/console/keymap.py b/mitmproxy/tools/console/keymap.py index 354b3aac..e406905d 100644 --- a/mitmproxy/tools/console/keymap.py +++ b/mitmproxy/tools/console/keymap.py @@ -19,7 +19,7 @@ Contexts = { class Binding: def __init__(self, key, command, contexts, help): - self.key, self.command, self.contexts = key, command, contexts + self.key, self.command, self.contexts = key, command, sorted(contexts) self.help = help def keyspec(self): @@ -29,6 +29,9 @@ class Binding: """ return self.key.replace("space", " ") + def sortkey(self): + return self.key + ",".join(self.contexts) + class Keymap: def __init__(self, master): @@ -56,16 +59,16 @@ class Keymap: Add a key to the key map. """ self._check_contexts(contexts) - self.remove(key, contexts) for b in self.bindings: - if b.key == key and b.command == command: - b.contexts = list(set(b.contexts + contexts)) + if b.key == key and b.command.strip() == command.strip(): + b.contexts = sorted(list(set(b.contexts + contexts))) if help: b.help = help self.bind(b) break else: + self.remove(key, contexts) b = Binding(key=key, command=command, contexts=contexts, help=help) self.bindings.append(b) self.bind(b) @@ -107,8 +110,8 @@ class Keymap: b = [x for x in self.bindings if context in x.contexts or context == "all"] single = [x for x in b if len(x.key.split()) == 1] multi = [x for x in b if len(x.key.split()) != 1] - single.sort(key=lambda x: x.key) - multi.sort(key=lambda x: x.key) + single.sort(key=lambda x: x.sortkey()) + multi.sort(key=lambda x: x.sortkey()) return single + multi def handle(self, context: str, key: str) -> typing.Optional[str]: |