From 6f7391d7d127e4081ed88751270b0216805ba508 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 24 Apr 2014 17:59:35 +0200 Subject: [PATCH] Leave insert mode in loadStarted --- TODO | 1 - qutebrowser/widgets/browsertab.py | 24 +++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index ab5002bcb..da196003d 100644 --- a/TODO +++ b/TODO @@ -3,7 +3,6 @@ keyparser foo - Create a SimpleKeyParser and inherit KeyParser from that. - Handle keybind to get out of insert mode (e.g. esc) -- Enter normal mode in loadingStarted already - Read unbound-keys setting only once - Add more element-selection-detection code (with options?) based on: -> javascript: http://stackoverflow.com/a/2848120/2085149 diff --git a/qutebrowser/widgets/browsertab.py b/qutebrowser/widgets/browsertab.py index 133732a29..4153e0cdf 100644 --- a/qutebrowser/widgets/browsertab.py +++ b/qutebrowser/widgets/browsertab.py @@ -86,6 +86,7 @@ class BrowserTab(QWebView): self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.page_.linkHovered.connect(self.linkHovered) self.linkClicked.connect(self.on_link_clicked) + self.loadStarted.connect(lambda: modemanager.maybe_leave("insert")) self.loadFinished.connect(self.on_load_finished) # FIXME find some way to hide scrollbars without setScrollBarPolicy @@ -245,21 +246,18 @@ class BrowserTab(QWebView): QApplication.postEvent(self, evt) @pyqtSlot(bool) - def on_load_finished(self, ok): - """Handle insert mode after loading finished.""" - if not ok: + def on_load_finished(self, _ok): + """Handle auto_insert_mode after loading finished.""" + if not config.get('general', 'auto_insert_mode'): + return + frame = self.page_.currentFrame() + elem = frame.findFirstElement( + webelem.SELECTORS['editable_focused']) + logging.debug("focus element: {}".format(not elem.isNull())) + if elem.isNull(): modemanager.maybe_leave("insert") - elif config.get('general', 'auto_insert_mode'): - frame = self.page_.currentFrame() - elem = frame.findFirstElement( - webelem.SELECTORS['editable_focused']) - logging.debug("focus element: {}".format(not elem.isNull())) - if elem.isNull(): - modemanager.maybe_leave("insert") - else: - modemanager.enter("insert") else: - modemanager.maybe_leave("insert") + modemanager.enter("insert") @pyqtSlot(str) def set_force_open_target(self, target):