From 975508f4ea9514bd69430a355c5d7b3577f5f20e Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Sun, 14 Oct 2018 23:51:42 -0700 Subject: [PATCH 1/5] Add setting to avoid leaving insert mode on load_started It looks like load_started can be emitted for a lot of things, such as an anchor change, and some people may not want to leave insert mode on reload anyway. --- qutebrowser/config/configdata.yml | 5 +++++ qutebrowser/mainwindow/tabbedbrowser.py | 11 +++++++---- tests/end2end/test_insert_mode.py | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index d30041712..5c6df6e35 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1270,6 +1270,11 @@ 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 + desc: Leave insert mode when starting a new page load. + input.links_included_in_focus_chain: default: true type: Bool diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 1f3484663..2adf8b0b4 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -584,10 +584,13 @@ 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) + if config.val.input.insert_mode.leave_on_load: + modeman.leave(self._win_id, usertypes.KeyMode.insert, + 'load started', maybe=True) + modeman.leave(self._win_id, usertypes.KeyMode.hint, + 'load started', maybe=True) + else: + log.modes.debug("Ignoring leave_on_load request due to setting.") @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 690b5d38b..6c85af3ed 100644 --- a/tests/end2end/test_insert_mode.py +++ b/tests/end2end/test_insert_mode.py @@ -85,3 +85,19 @@ 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.') From 3d5caba7d404b1ff99a9c5884d0d45677cb4c1d2 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Mon, 15 Oct 2018 19:11:32 -0700 Subject: [PATCH 2/5] Add rudimentary support for URL patterns in leave_on_load --- qutebrowser/config/configdata.yml | 7 ++++++- qutebrowser/mainwindow/tabbedbrowser.py | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 5c6df6e35..1be8c74b6 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1273,7 +1273,12 @@ input.insert_mode.plugins: input.insert_mode.leave_on_load: default: true type: Bool - desc: Leave insert mode when starting a new page load. + 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 diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 2adf8b0b4..19a6d67b2 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -584,7 +584,8 @@ class TabbedBrowser(QWidget): @pyqtSlot() def on_cur_load_started(self): """Leave insert/hint mode when loading started.""" - if config.val.input.insert_mode.leave_on_load: + if config.instance.get('input.insert_mode.leave_on_load', + url=self.current_url()): modeman.leave(self._win_id, usertypes.KeyMode.insert, 'load started', maybe=True) modeman.leave(self._win_id, usertypes.KeyMode.hint, From 0e327c4ec48f008aba19d7170b1ed8c2419a17a2 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Tue, 16 Oct 2018 18:42:37 -0700 Subject: [PATCH 3/5] Always leave hint mode - Also handle invalid URLs properly through catching the QtValueError --- qutebrowser/mainwindow/tabbedbrowser.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 19a6d67b2..092f18e2f 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -584,14 +584,18 @@ class TabbedBrowser(QWidget): @pyqtSlot() def on_cur_load_started(self): """Leave insert/hint mode when loading started.""" + try: + url = self.current_url() + except qtutils.QtValueError: + url = None if config.instance.get('input.insert_mode.leave_on_load', - url=self.current_url()): + url=url): modeman.leave(self._win_id, usertypes.KeyMode.insert, 'load started', maybe=True) - modeman.leave(self._win_id, usertypes.KeyMode.hint, - '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): From 3a9a75c1d5d19ab0842136a57b809a1444f32126 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 1 Feb 2019 23:25:22 -0800 Subject: [PATCH 4/5] Fix style issues --- qutebrowser/mainwindow/tabbedbrowser.py | 2 +- tests/end2end/test_insert_mode.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 8f2aa4e4f..46e4f6683 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -597,7 +597,7 @@ class TabbedBrowser(QWidget): else: log.modes.debug("Ignoring leave_on_load request due to setting.") modeman.leave(self._win_id, usertypes.KeyMode.hint, - 'load started', maybe=True) + '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 6c85af3ed..ead584363 100644 --- a/tests/end2end/test_insert_mode.py +++ b/tests/end2end/test_insert_mode.py @@ -92,7 +92,8 @@ 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.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') From afed360f16d7bcca1b6576ba427378ff265d13bd Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 22 Feb 2019 21:55:11 -0800 Subject: [PATCH 5/5] Double-check url is valid in leave_on_load --- qutebrowser/mainwindow/tabbedbrowser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 46e4f6683..2c9bde47e 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -588,6 +588,8 @@ class TabbedBrowser(QWidget): """Leave insert/hint mode when loading started.""" 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',