diff --git a/qutebrowser/app.py b/qutebrowser/app.py index d8c197dab..188efbd81 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -137,6 +137,7 @@ class QuteBrowser(QApplication): modes.manager.register('insert', self._keyparsers['insert'].handle, passthrough=True) modes.manager.register('command', None, passthrough=True) + self.modeman = modes.manager # for commands self.installEventFilter(modes.manager) self.setQuitOnLastWindowClosed(False) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 725683860..cea2e9d92 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -82,9 +82,7 @@ SECTION_DESC = { "Keybindings for insert mode.\n" "Since normal keypresses are passed through, only special keys are " "supported in this mode.\n" - "In addition to the normal commands, the following special commands " - "are defined:\n" - " : Leave the insert mode."), + "An useful command to map here is the hidden command leave_mode."), 'aliases': ( "Aliases for commands.\n" "By default, no aliases are defined. Example which adds a new command " @@ -428,9 +426,9 @@ DATA = OrderedDict([ )), ('keybind.insert', sect.ValueList( - types.KeyBindingName(), types.KeyBinding(['']), - ('', ''), - ('', ''), + types.KeyBindingName(), types.KeyBinding(), + ('', 'leave_mode'), + ('', 'leave_mode'), )), ('aliases', sect.ValueList( diff --git a/qutebrowser/config/conftypes.py b/qutebrowser/config/conftypes.py index afee10b86..832e61852 100644 --- a/qutebrowser/config/conftypes.py +++ b/qutebrowser/config/conftypes.py @@ -538,18 +538,6 @@ class LastClose(String): class KeyBinding(Command): - """The command of a keybinding. + """The command of a keybinding.""" - Attributes: - _special_keys: Specially defined keys which are no commands. - """ - - def __init__(self, special_keys=None): - if special_keys is None: - special_keys = [] - self._special_keys = special_keys - - def validate(self, value): - if value in self._special_keys: - return - super().validate(value) + pass diff --git a/qutebrowser/keyinput/insertmode.py b/qutebrowser/keyinput/insertmode.py index c429b045a..6b57b3822 100644 --- a/qutebrowser/keyinput/insertmode.py +++ b/qutebrowser/keyinput/insertmode.py @@ -18,18 +18,13 @@ """KeyParser for "insert" mode.""" import qutebrowser.keyinput.modes as modes -from qutebrowser.keyinput.keyparser import KeyParser +from qutebrowser.keyinput.keyparser import CommandKeyParser -class InsertKeyParser(KeyParser): +class InsertKeyParser(CommandKeyParser): """KeyParser for insert mode.""" def __init__(self, parent=None): super().__init__(parent, supports_chains=False) self.read_config('keybind.insert') - - def execute(self, cmdstr, _count=None): - """Handle a completed keychain.""" - if cmdstr == '': - modes.leave("insert") diff --git a/qutebrowser/keyinput/modes.py b/qutebrowser/keyinput/modes.py index e293edc5f..c143efb8e 100644 --- a/qutebrowser/keyinput/modes.py +++ b/qutebrowser/keyinput/modes.py @@ -26,6 +26,7 @@ import logging from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QEvent import qutebrowser.config.config as config +import qutebrowser.commands.utils as cmdutils manager = None @@ -150,6 +151,13 @@ class ModeManager(QObject): logging.debug("New mode stack: {}".format(self._mode_stack)) self.left.emit(mode) + # FIXME handle modes=[] and not_modes=[] params + @cmdutils.register(instance='modeman', name='leave_mode', hide=True) + def leave_current_mode(self): + if self.mode == "normal": + raise ValueError("Can't leave normal mode!") + self.leave(self.mode) + @pyqtSlot(str, str) def on_config_changed(self, section, option): """Update local setting when config changed."""