diff --git a/qutebrowser/commands/command.py b/qutebrowser/commands/command.py index 41d97481c..034039479 100644 --- a/qutebrowser/commands/command.py +++ b/qutebrowser/commands/command.py @@ -502,3 +502,12 @@ class Command: log.commands.debug('Calling {}'.format( debug_utils.format_call(self.handler, posargs, kwargs))) self.handler(*posargs, **kwargs) + + def mode_allowed(self, mode): + """Check if the command can be run in the given mode. + + Args: + mode: The mode to check. + """ + return ((self._modes is None or mode in self._modes) and + (self._not_modes is None or mode not in self._not_modes)) diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 22a715d15..78f691191 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -287,10 +287,7 @@ class CommandRunner(QObject): result.cmd.run(self._win_id, args) if (result.cmdline[0] != 'repeat-command' and - (result.cmd._modes is None or - usertypes.KeyMode.normal in result.cmd._modes) and - (result.cmd._not_modes is None or - usertypes.KeyMode.normal not in result.cmd._not_modes)): + result.cmd.mode_allowed(usertypes.KeyMode.normal)): global last_command last_command = (self._parse_count(text)[1], count if count is not None else result.count)