diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index b8f5235f4..e2d443280 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1236,6 +1236,16 @@ input.insert_mode.plugins: type: Bool desc: Switch to insert mode when clicking flash and other plugins. +input.insert_mode.leave_on_load: + default: true + type: Bool + supports_pattern: true + desc: >- + Leave insert mode when starting a new page load. + + Patterns may be unreliable on this setting, and they may match the url you + are navigating to, or the URL you are navigating from. + input.links_included_in_focus_chain: default: true type: Bool diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 1476d469d..11fe0b600 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -586,10 +586,20 @@ class TabbedBrowser(QWidget): @pyqtSlot() def on_cur_load_started(self): """Leave insert/hint mode when loading 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) + try: + url = self.current_url() + if not url.isValid(): + url = None + except qtutils.QtValueError: + url = None + if config.instance.get('input.insert_mode.leave_on_load', + url=url): + modeman.leave(self._win_id, usertypes.KeyMode.insert, + 'load started', maybe=True) + else: + log.modes.debug("Ignoring leave_on_load request due to setting.") + modeman.leave(self._win_id, usertypes.KeyMode.hint, + 'load started', maybe=True) @pyqtSlot(browsertab.AbstractTab, str) def on_title_changed(self, tab, text): diff --git a/tests/end2end/test_insert_mode.py b/tests/end2end/test_insert_mode.py index d9b7c3513..54e011df6 100644 --- a/tests/end2end/test_insert_mode.py +++ b/tests/end2end/test_insert_mode.py @@ -85,3 +85,20 @@ def test_auto_leave_insert_mode(quteproc): # Select the disabled input box to leave insert mode quteproc.send_cmd(':follow-hint s') quteproc.wait_for(message='Clicked non-editable element!') + + +@pytest.mark.parametrize('leave_on_load', [True, False]) +def test_auto_leave_insert_mode_reload(quteproc, leave_on_load): + url_path = 'data/hello.txt' + quteproc.open_path(url_path) + + quteproc.set_setting('input.insert_mode.leave_on_load', + str(leave_on_load).lower()) + quteproc.send_cmd(':enter-mode insert') + quteproc.wait_for(message='Entering mode KeyMode.insert (reason: *)') + quteproc.send_cmd(':reload') + if leave_on_load: + quteproc.wait_for(message='Leaving mode KeyMode.insert (reason: *)') + else: + quteproc.wait_for( + message='Ignoring leave_on_load request due to setting.')