Use normal command to leave insert mode
This commit is contained in:
parent
a1fd1537bd
commit
e06583ade2
@ -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)
|
||||
|
||||
|
@ -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>: 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(['<leave>']),
|
||||
('<Escape>', '<leave>'),
|
||||
('<Ctrl-C>', '<leave>'),
|
||||
types.KeyBindingName(), types.KeyBinding(),
|
||||
('<Escape>', 'leave_mode'),
|
||||
('<Ctrl-C>', 'leave_mode'),
|
||||
)),
|
||||
|
||||
('aliases', sect.ValueList(
|
||||
|
@ -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
|
||||
|
@ -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 == '<leave>':
|
||||
modes.leave("insert")
|
||||
|
@ -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."""
|
||||
|
Loading…
Reference in New Issue
Block a user