From ccc9d1779c3d753a9c2bc1d488ec32d85e7fc135 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 17 Jun 2020 13:16:14 +0200 Subject: 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. --- qutebrowser/keyinput/modeman.py | 56 ++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'qutebrowser/keyinput/modeman.py') 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 -- cgit v1.2.3-54-g00ecf