summaryrefslogtreecommitdiff
path: root/qutebrowser/keyinput/modeman.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-06-17 13:16:14 +0200
committerFlorian Bruhin <me@the-compiler.org>2020-06-17 14:12:24 +0200
commitccc9d1779c3d753a9c2bc1d488ec32d85e7fc135 (patch)
treeec080b64afec16390fd3d98338f24577733258c7 /qutebrowser/keyinput/modeman.py
parent03a5291d0596989bba8e056c9be06489330bb9d0 (diff)
downloadqutebrowser-ccc9d1779c3d753a9c2bc1d488ec32d85e7fc135.tar.gz
qutebrowser-ccc9d1779c3d753a9c2bc1d488ec32d85e7fc135.zip
modeparsers: Refactor to avoid subclassing
Before the changes in this commit, we've had to have a subclassed parser for every mode, even if there was no special key handling going on in that mode. With a couple of changes, we can avoid many of those subclasses and only have subclasses for bigger changes (like hint or register modes). - The awkward handling of self._modename in _read_config() is now removed. _read_config() doesn't take an argument, always uses the mode in self._mode and gets called from __init__. - BaseKeyParser takes the mode as an argument to __init__. - The class attributes (do_log/passthrough/supports_count) now also get passed via the constructor.
Diffstat (limited to 'qutebrowser/keyinput/modeman.py')
-rw-r--r--qutebrowser/keyinput/modeman.py56
1 files changed, 36 insertions, 20 deletions
diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py
index eb96020f3..2ec956422 100644
--- a/qutebrowser/keyinput/modeman.py
+++ b/qutebrowser/keyinput/modeman.py
@@ -102,70 +102,86 @@ def init(win_id: int, parent: QObject) -> 'ModeManager':
parent=modeman),
usertypes.KeyMode.insert:
- modeparsers.PassthroughKeyParser(
- win_id=win_id,
+ modeparsers.CommandKeyParser(
mode=usertypes.KeyMode.insert,
+ win_id=win_id,
commandrunner=commandrunner,
- parent=modeman),
+ parent=modeman,
+ passthrough=True,
+ do_log=False,
+ supports_count=False),
usertypes.KeyMode.passthrough:
- modeparsers.PassthroughKeyParser(
- win_id=win_id,
+ modeparsers.CommandKeyParser(
mode=usertypes.KeyMode.passthrough,
+ win_id=win_id,
commandrunner=commandrunner,
- parent=modeman),
+ parent=modeman,
+ passthrough=True,
+ do_log=False,
+ supports_count=False),
usertypes.KeyMode.command:
- modeparsers.PassthroughKeyParser(
- win_id=win_id,
+ modeparsers.CommandKeyParser(
mode=usertypes.KeyMode.command,
+ win_id=win_id,
commandrunner=commandrunner,
- parent=modeman),
+ parent=modeman,
+ passthrough=True,
+ do_log=False,
+ supports_count=False),
usertypes.KeyMode.prompt:
- modeparsers.PassthroughKeyParser(
- win_id=win_id,
+ modeparsers.CommandKeyParser(
mode=usertypes.KeyMode.prompt,
+ win_id=win_id,
commandrunner=commandrunner,
- parent=modeman),
+ parent=modeman,
+ passthrough=True,
+ do_log=False,
+ supports_count=False),
usertypes.KeyMode.yesno:
- modeparsers.PromptKeyParser(
+ modeparsers.CommandKeyParser(
+ mode=usertypes.KeyMode.yesno,
win_id=win_id,
commandrunner=commandrunner,
- parent=modeman),
+ parent=modeman,
+ supports_count=False),
usertypes.KeyMode.caret:
- modeparsers.CaretKeyParser(
+ modeparsers.CommandKeyParser(
+ mode=usertypes.KeyMode.caret,
win_id=win_id,
commandrunner=commandrunner,
- parent=modeman),
+ parent=modeman,
+ passthrough=True),
usertypes.KeyMode.set_mark:
modeparsers.RegisterKeyParser(
- win_id=win_id,
mode=usertypes.KeyMode.set_mark,
+ win_id=win_id,
commandrunner=commandrunner,
parent=modeman),
usertypes.KeyMode.jump_mark:
modeparsers.RegisterKeyParser(
- win_id=win_id,
mode=usertypes.KeyMode.jump_mark,
+ win_id=win_id,
commandrunner=commandrunner,
parent=modeman),
usertypes.KeyMode.record_macro:
modeparsers.RegisterKeyParser(
- win_id=win_id,
mode=usertypes.KeyMode.record_macro,
+ win_id=win_id,
commandrunner=commandrunner,
parent=modeman),
usertypes.KeyMode.run_macro:
modeparsers.RegisterKeyParser(
- win_id=win_id,
mode=usertypes.KeyMode.run_macro,
+ win_id=win_id,
commandrunner=commandrunner,
parent=modeman),
} # type: ParserDictType