Handle check for allowed mode better

This commit is contained in:
Jan Verbeek 2016-06-29 20:58:29 +02:00
parent cc1899ebca
commit f9afa190b1
2 changed files with 10 additions and 4 deletions

View File

@ -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))

View File

@ -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)