diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 50324f030..5db5fd2bc 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -57,6 +57,7 @@ import qutebrowser.utils.message as message from qutebrowser.widgets.mainwindow import MainWindow from qutebrowser.widgets.crash import CrashDialog from qutebrowser.keyinput.commandmode import CommandKeyParser +from qutebrowser.keyinput.insertmode import InsertKeyParser from qutebrowser.commands.parsers import CommandParser, SearchParser from qutebrowser.browser.hints import HintKeyParser from qutebrowser.utils.appdirs import AppDirs @@ -124,16 +125,18 @@ class QuteBrowser(QApplication): self.commandparser = CommandParser() self.searchparser = SearchParser() self._keyparsers = { - "normal": CommandKeyParser(self), - "hint": HintKeyParser(self), + 'normal': CommandKeyParser(self), + 'hint': HintKeyParser(self), + 'insert': InsertKeyParser(self), } self._init_cmds() self.mainwindow = MainWindow() modes.init(self) - modes.manager.register("normal", self._keyparsers["normal"].handle) - modes.manager.register("hint", self._keyparsers["hint"].handle) - modes.manager.register("insert", None, passthrough=True) - modes.manager.register("command", None, passthrough=True) + modes.manager.register('normal', self._keyparsers['normal'].handle) + modes.manager.register('hint', self._keyparsers['hint'].handle) + modes.manager.register('insert', self._keyparsers['insert'].handle, + passthrough=True) + modes.manager.register('command', None, passthrough=True) self.installEventFilter(modes.manager) self.setQuitOnLastWindowClosed(False) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 7f34399fa..9719fc207 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -78,6 +78,13 @@ SECTION_DESC = { "pressed with Shift. For special keys (with <>-signs), you need " "to explicitely add \"Shift-\" to match a key pressed with shift. " "You can bind multiple commands by separating them with \";;\"."), + 'keybind.insert': ( + "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" + " : Switch back to normal mode."), 'aliases': ( "Aliases for commands.\n" "By default, no aliases are defined. Example which adds a new command " @@ -420,6 +427,12 @@ DATA = OrderedDict([ ('', 'back'), )), + ('keybind.insert', sect.ValueList( + types.KeyBindingName(), types.KeyBinding(['']), + ('', ''), + ('', ''), + )), + ('aliases', sect.ValueList( types.Command(), types.Command(), )), diff --git a/qutebrowser/config/conftypes.py b/qutebrowser/config/conftypes.py index 832e61852..5694cfa03 100644 --- a/qutebrowser/config/conftypes.py +++ b/qutebrowser/config/conftypes.py @@ -538,6 +538,18 @@ class LastClose(String): class KeyBinding(Command): - """The command of a keybinding.""" + """The command of a keybinding. - pass + Attributes: + _special_keys: Specially defined keys which are no commands. + """ + + def __init__(self, special_keys=None): + if special_keys == None: + special_keys = [] + self._special_keys = special_keys + + def validate(self, value): + if value in self._special_keys: + return + super().validate(value) diff --git a/qutebrowser/keyinput/insertmode.py b/qutebrowser/keyinput/insertmode.py new file mode 100644 index 000000000..fbeba0300 --- /dev/null +++ b/qutebrowser/keyinput/insertmode.py @@ -0,0 +1,37 @@ +# Copyright 2014 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""KeyParser for "insert" mode.""" + +from PyQt5.QtCore import pyqtSignal, Qt + +import qutebrowser.keyinput.modes as modes +from qutebrowser.keyinput.keyparser import KeyParser + + +class InsertKeyParser(KeyParser): + + """KeyParser for insert mode.""" + + def __init__(self, parent=None): + super().__init__(parent) + self.read_config('keybind.insert') + + def execute(self, cmdstr, count=None): + """Handle a completed keychain.""" + if cmdstr == '': + modes.leave("insert")