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,
|
modes.manager.register('insert', self._keyparsers['insert'].handle,
|
||||||
passthrough=True)
|
passthrough=True)
|
||||||
modes.manager.register('command', None, passthrough=True)
|
modes.manager.register('command', None, passthrough=True)
|
||||||
|
self.modeman = modes.manager # for commands
|
||||||
self.installEventFilter(modes.manager)
|
self.installEventFilter(modes.manager)
|
||||||
self.setQuitOnLastWindowClosed(False)
|
self.setQuitOnLastWindowClosed(False)
|
||||||
|
|
||||||
|
@ -82,9 +82,7 @@ SECTION_DESC = {
|
|||||||
"Keybindings for insert mode.\n"
|
"Keybindings for insert mode.\n"
|
||||||
"Since normal keypresses are passed through, only special keys are "
|
"Since normal keypresses are passed through, only special keys are "
|
||||||
"supported in this mode.\n"
|
"supported in this mode.\n"
|
||||||
"In addition to the normal commands, the following special commands "
|
"An useful command to map here is the hidden command leave_mode."),
|
||||||
"are defined:\n"
|
|
||||||
" <leave>: Leave the insert mode."),
|
|
||||||
'aliases': (
|
'aliases': (
|
||||||
"Aliases for commands.\n"
|
"Aliases for commands.\n"
|
||||||
"By default, no aliases are defined. Example which adds a new command "
|
"By default, no aliases are defined. Example which adds a new command "
|
||||||
@ -428,9 +426,9 @@ DATA = OrderedDict([
|
|||||||
)),
|
)),
|
||||||
|
|
||||||
('keybind.insert', sect.ValueList(
|
('keybind.insert', sect.ValueList(
|
||||||
types.KeyBindingName(), types.KeyBinding(['<leave>']),
|
types.KeyBindingName(), types.KeyBinding(),
|
||||||
('<Escape>', '<leave>'),
|
('<Escape>', 'leave_mode'),
|
||||||
('<Ctrl-C>', '<leave>'),
|
('<Ctrl-C>', 'leave_mode'),
|
||||||
)),
|
)),
|
||||||
|
|
||||||
('aliases', sect.ValueList(
|
('aliases', sect.ValueList(
|
||||||
|
@ -538,18 +538,6 @@ class LastClose(String):
|
|||||||
|
|
||||||
class KeyBinding(Command):
|
class KeyBinding(Command):
|
||||||
|
|
||||||
"""The command of a keybinding.
|
"""The command of a keybinding."""
|
||||||
|
|
||||||
Attributes:
|
pass
|
||||||
_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)
|
|
||||||
|
@ -18,18 +18,13 @@
|
|||||||
"""KeyParser for "insert" mode."""
|
"""KeyParser for "insert" mode."""
|
||||||
|
|
||||||
import qutebrowser.keyinput.modes as modes
|
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."""
|
"""KeyParser for insert mode."""
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent, supports_chains=False)
|
super().__init__(parent, supports_chains=False)
|
||||||
self.read_config('keybind.insert')
|
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
|
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QEvent
|
||||||
|
|
||||||
import qutebrowser.config.config as config
|
import qutebrowser.config.config as config
|
||||||
|
import qutebrowser.commands.utils as cmdutils
|
||||||
|
|
||||||
|
|
||||||
manager = None
|
manager = None
|
||||||
@ -150,6 +151,13 @@ class ModeManager(QObject):
|
|||||||
logging.debug("New mode stack: {}".format(self._mode_stack))
|
logging.debug("New mode stack: {}".format(self._mode_stack))
|
||||||
self.left.emit(mode)
|
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)
|
@pyqtSlot(str, str)
|
||||||
def on_config_changed(self, section, option):
|
def on_config_changed(self, section, option):
|
||||||
"""Update local setting when config changed."""
|
"""Update local setting when config changed."""
|
||||||
|
Loading…
Reference in New Issue
Block a user