Use normal commands for hint mode
This commit is contained in:
parent
540c134f06
commit
926194849c
@ -272,7 +272,6 @@ class QuteBrowser(QApplication):
|
||||
|
||||
# hints
|
||||
kp["hint"].fire_hint.connect(tabs.cur.fire_hint)
|
||||
kp["hint"].abort_hinting.connect(tabs.cur.abort_hinting)
|
||||
kp["hint"].keystring_updated.connect(tabs.cur.handle_hint_key)
|
||||
tabs.hint_strings_updated.connect(kp["hint"].on_hint_strings_updated)
|
||||
|
||||
|
@ -207,11 +207,6 @@ class CurCommandDispatcher(QObject):
|
||||
"""Fire a completed hint."""
|
||||
self._tabs.currentWidget().hintmanager.fire(keystr)
|
||||
|
||||
@pyqtSlot()
|
||||
def abort_hinting(self):
|
||||
"""Abort hinting."""
|
||||
self._tabs.currentWidget().hintmanager.stop()
|
||||
|
||||
@pyqtSlot(str, int)
|
||||
def search(self, text, flags):
|
||||
"""Search for text in the current page.
|
||||
|
@ -91,6 +91,7 @@ class HintManager(QObject):
|
||||
self._frame = None
|
||||
self._target = None
|
||||
self._baseurl = None
|
||||
modes.manager.left.connect(self.on_mode_left)
|
||||
|
||||
def _hint_strings(self, elems):
|
||||
"""Calculate the hint strings for elems.
|
||||
@ -302,18 +303,6 @@ class HintManager(QObject):
|
||||
self.hint_strings_updated.emit(strings)
|
||||
modes.enter("hint")
|
||||
|
||||
def stop(self):
|
||||
"""Stop hinting."""
|
||||
for elem in self._elems.values():
|
||||
elem.label.removeFromDocument()
|
||||
self._frame.contentsSizeChanged.disconnect(
|
||||
self.on_contents_size_changed)
|
||||
self._elems = {}
|
||||
self._target = None
|
||||
self._frame = None
|
||||
modes.leave("hint")
|
||||
message.clear()
|
||||
|
||||
def handle_partial_key(self, keystr):
|
||||
"""Handle a new partial keypress."""
|
||||
delete = []
|
||||
@ -355,7 +344,7 @@ class HintManager(QObject):
|
||||
message.set_cmd_text(':{} {}'.format(commands[self._target],
|
||||
urlutils.urlstring(link)))
|
||||
if self._target != 'rapid':
|
||||
self.stop()
|
||||
modes.leave("hint")
|
||||
|
||||
@pyqtSlot('QSize')
|
||||
def on_contents_size_changed(self, _size):
|
||||
@ -365,3 +354,17 @@ class HintManager(QObject):
|
||||
css = self.HINT_CSS.format(left=rect.x(), top=rect.y(),
|
||||
config=config.instance)
|
||||
elems.label.setAttribute("style", css)
|
||||
|
||||
@pyqtSlot(str)
|
||||
def on_mode_left(self, mode):
|
||||
"""Stop hinting when hinting mode was left."""
|
||||
if mode != "hint":
|
||||
return
|
||||
for elem in self._elems.values():
|
||||
elem.label.removeFromDocument()
|
||||
self._frame.contentsSizeChanged.disconnect(
|
||||
self.on_contents_size_changed)
|
||||
self._elems = {}
|
||||
self._target = None
|
||||
self._frame = None
|
||||
message.clear()
|
||||
|
@ -83,6 +83,11 @@ SECTION_DESC = {
|
||||
"Since normal keypresses are passed through, only special keys are "
|
||||
"supported in this mode.\n"
|
||||
"An useful command to map here is the hidden command leave_mode."),
|
||||
'keybind.hint': (
|
||||
"Keybindings for hint mode.\n"
|
||||
"Since normal keypresses are passed through, only special keys are "
|
||||
"supported in this mode.\n"
|
||||
"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 "
|
||||
@ -431,6 +436,12 @@ DATA = OrderedDict([
|
||||
('<Ctrl-C>', 'leave_mode'),
|
||||
)),
|
||||
|
||||
('keybind.hint', sect.ValueList(
|
||||
types.KeyBindingName(), types.KeyBinding(),
|
||||
('<Escape>', 'leave_mode'),
|
||||
('<Ctrl-C>', 'leave_mode'),
|
||||
)),
|
||||
|
||||
('aliases', sect.ValueList(
|
||||
types.Command(), types.Command(),
|
||||
)),
|
||||
|
@ -19,46 +19,35 @@
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, Qt
|
||||
|
||||
from qutebrowser.keyinput.keyparser import KeyParser
|
||||
from qutebrowser.keyinput.keyparser import CommandKeyParser
|
||||
|
||||
|
||||
class HintKeyParser(KeyParser):
|
||||
class HintKeyParser(CommandKeyParser):
|
||||
|
||||
"""KeyChainParser for hints.
|
||||
|
||||
Signals:
|
||||
fire_hint: When a hint keybinding was completed.
|
||||
Arg: the keystring/hint string pressed.
|
||||
abort_hinting: Esc pressed, so abort hinting.
|
||||
"""
|
||||
|
||||
fire_hint = pyqtSignal(str)
|
||||
abort_hinting = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent, supports_count=False, supports_chains=True)
|
||||
self.read_config('keybind.hint')
|
||||
|
||||
def _handle_special_key(self, e):
|
||||
"""Handle the escape key.
|
||||
|
||||
FIXME make this more generic
|
||||
|
||||
Emit:
|
||||
abort_hinting: Emitted if hinting was aborted.
|
||||
"""
|
||||
if e.key() == Qt.Key_Escape:
|
||||
self._keystring = ''
|
||||
self.abort_hinting.emit()
|
||||
return True
|
||||
return False
|
||||
|
||||
def execute(self, cmdstr, _count=None):
|
||||
def execute(self, cmdstr, keytype, count=None):
|
||||
"""Handle a completed keychain.
|
||||
|
||||
Emit:
|
||||
fire_hint: Always emitted.
|
||||
fire_hint: Emitted if keytype is TYPE_CHAIN
|
||||
"""
|
||||
if keytype == self.TYPE_CHAIN:
|
||||
self.fire_hint.emit(cmdstr)
|
||||
else:
|
||||
# execute as command
|
||||
super().execute(cmdstr, keytype, count)
|
||||
|
||||
def on_hint_strings_updated(self, strings):
|
||||
"""Handler for HintManager's hint_strings_updated.
|
||||
|
Loading…
Reference in New Issue
Block a user