Get rid of modeman.maybe_leave
This commit is contained in:
parent
2ef85d6c35
commit
bbd842bd82
@ -742,8 +742,8 @@ class CommandDispatcher:
|
||||
message.info("{} {} yanked to {}".format(
|
||||
len(s), "char" if len(s) == 1 else "chars", target))
|
||||
if not keep:
|
||||
modeman.maybe_leave(self._win_id, KeyMode.caret,
|
||||
"yank selected")
|
||||
modeman.leave(self._win_id, KeyMode.caret, "yank selected",
|
||||
maybe=True)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
@cmdutils.argument('count', count=True)
|
||||
|
@ -50,7 +50,8 @@ class HintingError(Exception):
|
||||
def on_mode_entered(mode, win_id):
|
||||
"""Stop hinting when insert mode was entered."""
|
||||
if mode == usertypes.KeyMode.insert:
|
||||
modeman.maybe_leave(win_id, usertypes.KeyMode.hint, 'insert mode')
|
||||
modeman.leave(win_id, usertypes.KeyMode.hint, 'insert mode',
|
||||
maybe=True)
|
||||
|
||||
|
||||
class HintLabel(QLabel):
|
||||
@ -859,8 +860,8 @@ class HintManager(QObject):
|
||||
raise ValueError("No suitable handler found!")
|
||||
|
||||
if not self._context.rapid:
|
||||
modeman.maybe_leave(self._win_id, usertypes.KeyMode.hint,
|
||||
'followed')
|
||||
modeman.leave(self._win_id, usertypes.KeyMode.hint, 'followed',
|
||||
maybe=True)
|
||||
else:
|
||||
# Reset filtering
|
||||
self.filter_hints(None)
|
||||
|
@ -151,9 +151,8 @@ class MouseEventFilter(QObject):
|
||||
else:
|
||||
log.mouse.debug("Clicked non-editable element!")
|
||||
if config.get('input', 'auto-leave-insert-mode'):
|
||||
modeman.maybe_leave(self._tab.win_id,
|
||||
usertypes.KeyMode.insert,
|
||||
'click')
|
||||
modeman.leave(self._tab.win_id, usertypes.KeyMode.insert,
|
||||
'click', maybe=True)
|
||||
|
||||
def _mouserelease_insertmode(self):
|
||||
"""If we have an insertmode check scheduled, handle it."""
|
||||
@ -174,9 +173,8 @@ class MouseEventFilter(QObject):
|
||||
else:
|
||||
log.mouse.debug("Clicked non-editable element (delayed)!")
|
||||
if config.get('input', 'auto-leave-insert-mode'):
|
||||
modeman.maybe_leave(self._tab.win_id,
|
||||
usertypes.KeyMode.insert,
|
||||
'click-delayed')
|
||||
modeman.leave(self._tab.win_id, usertypes.KeyMode.insert,
|
||||
'click-delayed', maybe=True)
|
||||
|
||||
self._tab.elements.find_focused(mouserelease_insertmode_cb)
|
||||
|
||||
|
@ -106,18 +106,9 @@ def enter(win_id, mode, reason=None, only_if_normal=False):
|
||||
instance(win_id).enter(mode, reason, only_if_normal)
|
||||
|
||||
|
||||
def leave(win_id, mode, reason=None):
|
||||
def leave(win_id, mode, reason=None, *, maybe=False):
|
||||
"""Leave the mode 'mode'."""
|
||||
instance(win_id).leave(mode, reason)
|
||||
|
||||
|
||||
def maybe_leave(win_id, mode, reason=None):
|
||||
"""Convenience method to leave 'mode' without exceptions."""
|
||||
try:
|
||||
instance(win_id).leave(mode, reason)
|
||||
except NotInModeError as e:
|
||||
# This is rather likely to happen, so we only log to debug log.
|
||||
log.modes.debug("{} (leave reason: {})".format(e, reason))
|
||||
instance(win_id).leave(mode, reason, maybe=maybe)
|
||||
|
||||
|
||||
class ModeManager(QObject):
|
||||
|
@ -314,8 +314,8 @@ class PromptContainer(QWidget):
|
||||
if not question.interrupted:
|
||||
# If this question was interrupted, we already connected the signal
|
||||
question.aborted.connect(
|
||||
lambda: modeman.maybe_leave(self._win_id, prompt.KEY_MODE,
|
||||
'aborted'))
|
||||
lambda: modeman.leave(self._win_id, prompt.KEY_MODE, 'aborted',
|
||||
maybe=True))
|
||||
modeman.enter(self._win_id, prompt.KEY_MODE, 'question asked')
|
||||
|
||||
self.setSizePolicy(prompt.sizePolicy())
|
||||
@ -328,7 +328,7 @@ class PromptContainer(QWidget):
|
||||
@pyqtSlot(usertypes.KeyMode)
|
||||
def _on_prompt_done(self, key_mode):
|
||||
"""Leave the prompt mode in this window if a question was answered."""
|
||||
modeman.maybe_leave(self._win_id, key_mode, ':prompt-accept')
|
||||
modeman.leave(self._win_id, key_mode, ':prompt-accept', maybe=True)
|
||||
|
||||
@pyqtSlot(usertypes.KeyMode)
|
||||
def _on_global_mode_left(self, mode):
|
||||
@ -339,7 +339,7 @@ class PromptContainer(QWidget):
|
||||
"""
|
||||
if mode not in [usertypes.KeyMode.prompt, usertypes.KeyMode.yesno]:
|
||||
return
|
||||
modeman.maybe_leave(self._win_id, mode, 'left in other window')
|
||||
modeman.leave(self._win_id, mode, 'left in other window', maybe=True)
|
||||
item = self._layout.takeAt(0)
|
||||
if item is not None:
|
||||
widget = item.widget()
|
||||
|
@ -473,10 +473,10 @@ class TabbedBrowser(tabwidget.TabWidget):
|
||||
@pyqtSlot()
|
||||
def on_cur_load_started(self):
|
||||
"""Leave insert/hint mode when loading started."""
|
||||
modeman.maybe_leave(self._win_id, usertypes.KeyMode.insert,
|
||||
'load started')
|
||||
modeman.maybe_leave(self._win_id, usertypes.KeyMode.hint,
|
||||
'load started')
|
||||
modeman.leave(self._win_id, usertypes.KeyMode.insert, 'load started',
|
||||
maybe=True)
|
||||
modeman.leave(self._win_id, usertypes.KeyMode.hint, 'load started',
|
||||
maybe=True)
|
||||
|
||||
@pyqtSlot(browsertab.AbstractTab, str)
|
||||
def on_title_changed(self, tab, text):
|
||||
@ -567,7 +567,7 @@ class TabbedBrowser(tabwidget.TabWidget):
|
||||
tab.setFocus()
|
||||
for mode in [usertypes.KeyMode.hint, usertypes.KeyMode.insert,
|
||||
usertypes.KeyMode.caret, usertypes.KeyMode.passthrough]:
|
||||
modeman.maybe_leave(self._win_id, mode, 'tab changed')
|
||||
modeman.leave(self._win_id, mode, 'tab changed', maybe=True)
|
||||
if self._now_focused is not None:
|
||||
objreg.register('last-focused-tab', self._now_focused, update=True,
|
||||
scope='window', window=self._win_id)
|
||||
|
Loading…
Reference in New Issue
Block a user