From f7a08dfd345659114d07e0e0bebe79523da82558 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 16:57:05 -0500 Subject: [PATCH 01/19] use tabs.mode_on_change to persist or restore mode --- qutebrowser/mainwindow/tabbedbrowser.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index c51a7aaff..9c140f8a7 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -649,17 +649,23 @@ class TabbedBrowser(tabwidget.TabWidget): log.webview.debug("on_current_changed got called with invalid " "index {}".format(idx)) return + if self._now_focused and config.val.tabs.mode_on_change == 'restore': + current_mode = modeman.instance(self._win_id).mode + if not current_mode in (usertypes.KeyMode.insert,usertypes.KeyMode.passthrough): + current_mode = usertypes.KeyMode.normal + self._now_focused.data.input_mode = current_mode log.modes.debug("Current tab changed, focusing {!r}".format(tab)) tab.setFocus() modes_to_leave = [usertypes.KeyMode.hint, usertypes.KeyMode.caret] - if not config.val.tabs.persist_mode_on_change: + if not config.val.tabs.mode_on_change == 'persist': modes_to_leave += [usertypes.KeyMode.insert, usertypes.KeyMode.passthrough] for mode in modes_to_leave: modeman.leave(self._win_id, mode, 'tab changed', maybe=True) - + if config.val.tabs.mode_on_change == 'restore': + modeman.enter(self._win_id, tab.data.input_mode, 'restore input mode for tab') if self._now_focused is not None: objreg.register('last-focused-tab', self._now_focused, update=True, scope='window', window=self._win_id) From c87d8d0d8f6c2a383ee98500f28991ecca76ad4a Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 17:02:34 -0500 Subject: [PATCH 02/19] add propery to save tab input mode --- qutebrowser/browser/browsertab.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index eb0e55c4b..9b59f64fc 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -107,6 +107,7 @@ class TabData: override_target = attr.ib(None) pinned = attr.ib(False) fullscreen = attr.ib(False) + input_mode = usertypes.KeyMode.normal class AbstractAction: From 5dbfff016e70941f86c3a2a95dd90e4bb644c2f4 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 17:05:47 -0500 Subject: [PATCH 03/19] replace persist_mode_on_change with mode_on_change supports old persist_mode_on_change functionality or new save/restore mode --- qutebrowser/config/configdata.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index a118a8b59..ebe52b7ea 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1251,10 +1251,15 @@ tabs.padding: type: Padding desc: Padding (in pixels) around text for tabs. -tabs.persist_mode_on_change: - default: false - type: Bool - desc: Stay in insert/passthrough mode when switching tabs. +tabs.mode_on_change: + default: normal + type: + name: String + valid_values: + - persist: "retain the current mode." + - restore: "restore previously saved mode" + - normal: "always revert to normal mode" + desc: When switching tabs, what input mode is applied. tabs.position: default: top From 81b85994a12dd2cbf19b6b118496743eb6f7135b Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sun, 14 Jan 2018 13:29:51 -0500 Subject: [PATCH 04/19] document code a bit more --- qutebrowser/browser/browsertab.py | 1 + qutebrowser/mainwindow/tabbedbrowser.py | 1 + 2 files changed, 2 insertions(+) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 9b59f64fc..c9d2f540a 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -99,6 +99,7 @@ class TabData: Only used for QtWebKit. pinned: Flag to pin the tab. fullscreen: Whether the tab has a video shown fullscreen currently. + input_mode: current input mode for the tab. (insert, passthrough, normal) """ keep_icon = attr.ib(False) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 9c140f8a7..896e2f8ab 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -651,6 +651,7 @@ class TabbedBrowser(tabwidget.TabWidget): return if self._now_focused and config.val.tabs.mode_on_change == 'restore': current_mode = modeman.instance(self._win_id).mode + # only save insert & passthrough mode. otherwise default to normal if not current_mode in (usertypes.KeyMode.insert,usertypes.KeyMode.passthrough): current_mode = usertypes.KeyMode.normal self._now_focused.data.input_mode = current_mode From 05d076ba9f9c40e414ed0ca40326d35044d7005d Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 09:00:06 -0500 Subject: [PATCH 05/19] fix asciidoc for tabs.mode_on_change --- doc/help/settings.asciidoc | 18 ++++++++++++------ qutebrowser/config/configdata.yml | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 53af8399d..6b5fe34c9 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -241,7 +241,7 @@ |<>|Position of new tabs opened from another tab. |<>|Position of new tabs which aren't opened from another tab. |<>|Padding (in pixels) around text for tabs. -|<>|Stay in insert/passthrough mode when switching tabs. +|<>|Set input mode behavior when switching tab. |<>|Shrink pinned tabs down to their contents. |<>|Position of the tab bar. |<>|Which tab to select when the focused tab is removed. @@ -2824,13 +2824,19 @@ Default: - +pass:[right]+: +pass:[5]+ - +pass:[top]+: +pass:[0]+ -[[tabs.persist_mode_on_change]] -=== tabs.persist_mode_on_change -Stay in insert/passthrough mode when switching tabs. +[[tabs.mode_on_change]] +=== tabs.mode_on_change +When switching tabs, what input mode is applied. -Type: <> +Type: <> -Default: +pass:[false]+ +Valid values: + + * +persist+: Retain the current mode. + * +restore+: Restore previously saved mode. + * +normal+: Always revert to normal mode. + +Default: +pass:[normal]+ [[tabs.pinned.shrink]] === tabs.pinned.shrink diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index ebe52b7ea..921034288 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1256,9 +1256,9 @@ tabs.mode_on_change: type: name: String valid_values: - - persist: "retain the current mode." - - restore: "restore previously saved mode" - - normal: "always revert to normal mode" + - persist: "Retain the current mode." + - restore: "Restore previously saved mode." + - normal: "Always revert to normal mode." desc: When switching tabs, what input mode is applied. tabs.position: From 7d620a4bfc80c3120071d91cb3492111621ed3de Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 13:39:42 -0500 Subject: [PATCH 06/19] fix pylint/flake8 errors --- qutebrowser/mainwindow/tabbedbrowser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 896e2f8ab..b325b5e1c 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -652,7 +652,8 @@ class TabbedBrowser(tabwidget.TabWidget): if self._now_focused and config.val.tabs.mode_on_change == 'restore': current_mode = modeman.instance(self._win_id).mode # only save insert & passthrough mode. otherwise default to normal - if not current_mode in (usertypes.KeyMode.insert,usertypes.KeyMode.passthrough): + input_modes = (usertypes.KeyMode.insert, usertypes.KeyMode.passthrough) + if current_mode not in input_modes: current_mode = usertypes.KeyMode.normal self._now_focused.data.input_mode = current_mode From 9bb256b54502c1c463a1d631b9fccdd2d88bcc03 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 16:19:38 -0500 Subject: [PATCH 07/19] shorten lines --- qutebrowser/browser/browsertab.py | 2 +- qutebrowser/mainwindow/tabbedbrowser.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index c9d2f540a..41e4f1eaf 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -99,7 +99,7 @@ class TabData: Only used for QtWebKit. pinned: Flag to pin the tab. fullscreen: Whether the tab has a video shown fullscreen currently. - input_mode: current input mode for the tab. (insert, passthrough, normal) + input_mode: current input mode for the tab. """ keep_icon = attr.ib(False) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index b325b5e1c..0d1487f50 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -652,8 +652,8 @@ class TabbedBrowser(tabwidget.TabWidget): if self._now_focused and config.val.tabs.mode_on_change == 'restore': current_mode = modeman.instance(self._win_id).mode # only save insert & passthrough mode. otherwise default to normal - input_modes = (usertypes.KeyMode.insert, usertypes.KeyMode.passthrough) - if current_mode not in input_modes: + modes = (usertypes.KeyMode.insert, usertypes.KeyMode.passthrough) + if current_mode not in modes: current_mode = usertypes.KeyMode.normal self._now_focused.data.input_mode = current_mode @@ -667,7 +667,8 @@ class TabbedBrowser(tabwidget.TabWidget): for mode in modes_to_leave: modeman.leave(self._win_id, mode, 'tab changed', maybe=True) if config.val.tabs.mode_on_change == 'restore': - modeman.enter(self._win_id, tab.data.input_mode, 'restore input mode for tab') + modeman.enter(self._win_id, tab.data.input_mode, + 'restore input mode for tab') if self._now_focused is not None: objreg.register('last-focused-tab', self._now_focused, update=True, scope='window', window=self._win_id) From 9e524e4be8190ab2c4d90766d5d0633dae858b1c Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 16:57:05 -0500 Subject: [PATCH 08/19] use tabs.mode_on_change to persist or restore mode --- qutebrowser/mainwindow/tabbedbrowser.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 824abf25b..4c8a81df3 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -651,17 +651,23 @@ class TabbedBrowser(tabwidget.TabWidget): log.webview.debug("on_current_changed got called with invalid " "index {}".format(idx)) return + if self._now_focused and config.val.tabs.mode_on_change == 'restore': + current_mode = modeman.instance(self._win_id).mode + if not current_mode in (usertypes.KeyMode.insert,usertypes.KeyMode.passthrough): + current_mode = usertypes.KeyMode.normal + self._now_focused.data.input_mode = current_mode log.modes.debug("Current tab changed, focusing {!r}".format(tab)) tab.setFocus() modes_to_leave = [usertypes.KeyMode.hint, usertypes.KeyMode.caret] - if not config.val.tabs.persist_mode_on_change: + if not config.val.tabs.mode_on_change == 'persist': modes_to_leave += [usertypes.KeyMode.insert, usertypes.KeyMode.passthrough] for mode in modes_to_leave: modeman.leave(self._win_id, mode, 'tab changed', maybe=True) - + if config.val.tabs.mode_on_change == 'restore': + modeman.enter(self._win_id, tab.data.input_mode, 'restore input mode for tab') if self._now_focused is not None: objreg.register('last-focused-tab', self._now_focused, update=True, scope='window', window=self._win_id) From eb7e114e5f0064ee9c0b03a782435991bd4bcf85 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 17:02:34 -0500 Subject: [PATCH 09/19] add propery to save tab input mode --- qutebrowser/browser/browsertab.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 2c0aa6722..893bbfd38 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -105,6 +105,7 @@ class TabData: override_target = attr.ib(None) pinned = attr.ib(False) fullscreen = attr.ib(False) + input_mode = usertypes.KeyMode.normal class AbstractAction: From a7db197e45d341e4b85def4102d205f09b2d1fb4 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 12 Jan 2018 17:05:47 -0500 Subject: [PATCH 10/19] replace persist_mode_on_change with mode_on_change supports old persist_mode_on_change functionality or new save/restore mode --- qutebrowser/config/configdata.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index e2daefe3b..680210175 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1251,10 +1251,15 @@ tabs.padding: type: Padding desc: Padding (in pixels) around text for tabs. -tabs.persist_mode_on_change: - default: false - type: Bool - desc: Stay in insert/passthrough mode when switching tabs. +tabs.mode_on_change: + default: normal + type: + name: String + valid_values: + - persist: "retain the current mode." + - restore: "restore previously saved mode" + - normal: "always revert to normal mode" + desc: When switching tabs, what input mode is applied. tabs.position: default: top From 21fc848839b6ae7502ff97b72fa87edc8013133d Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sun, 14 Jan 2018 13:29:51 -0500 Subject: [PATCH 11/19] document code a bit more --- qutebrowser/browser/browsertab.py | 1 + qutebrowser/mainwindow/tabbedbrowser.py | 1 + 2 files changed, 2 insertions(+) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index 893bbfd38..a8ffedc01 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -98,6 +98,7 @@ class TabData: Only used for QtWebKit. pinned: Flag to pin the tab. fullscreen: Whether the tab has a video shown fullscreen currently. + input_mode: current input mode for the tab. (insert, passthrough, normal) """ keep_icon = attr.ib(False) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 4c8a81df3..59e566a5a 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -653,6 +653,7 @@ class TabbedBrowser(tabwidget.TabWidget): return if self._now_focused and config.val.tabs.mode_on_change == 'restore': current_mode = modeman.instance(self._win_id).mode + # only save insert & passthrough mode. otherwise default to normal if not current_mode in (usertypes.KeyMode.insert,usertypes.KeyMode.passthrough): current_mode = usertypes.KeyMode.normal self._now_focused.data.input_mode = current_mode From f3b52aaf23f37c30f10136b4bd6def5074c99c76 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 09:00:06 -0500 Subject: [PATCH 12/19] fix asciidoc for tabs.mode_on_change --- doc/help/settings.asciidoc | 18 ++++++++++++------ qutebrowser/config/configdata.yml | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index c44dfb9a6..279e7889e 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -242,7 +242,7 @@ |<>|Position of new tabs opened from another tab. |<>|Position of new tabs which aren't opened from another tab. |<>|Padding (in pixels) around text for tabs. -|<>|Stay in insert/passthrough mode when switching tabs. +|<>|Set input mode behavior when switching tab. |<>|Shrink pinned tabs down to their contents. |<>|Position of the tab bar. |<>|Which tab to select when the focused tab is removed. @@ -2825,13 +2825,19 @@ Default: - +pass:[right]+: +pass:[5]+ - +pass:[top]+: +pass:[0]+ -[[tabs.persist_mode_on_change]] -=== tabs.persist_mode_on_change -Stay in insert/passthrough mode when switching tabs. +[[tabs.mode_on_change]] +=== tabs.mode_on_change +When switching tabs, what input mode is applied. -Type: <> +Type: <> -Default: +pass:[false]+ +Valid values: + + * +persist+: Retain the current mode. + * +restore+: Restore previously saved mode. + * +normal+: Always revert to normal mode. + +Default: +pass:[normal]+ [[tabs.pinned.shrink]] === tabs.pinned.shrink diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 680210175..5e47eb84e 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1256,9 +1256,9 @@ tabs.mode_on_change: type: name: String valid_values: - - persist: "retain the current mode." - - restore: "restore previously saved mode" - - normal: "always revert to normal mode" + - persist: "Retain the current mode." + - restore: "Restore previously saved mode." + - normal: "Always revert to normal mode." desc: When switching tabs, what input mode is applied. tabs.position: From 91b70fab70e1688d768d2bc16efe73c590e4931a Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 13:39:42 -0500 Subject: [PATCH 13/19] fix pylint/flake8 errors --- qutebrowser/mainwindow/tabbedbrowser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 59e566a5a..617981988 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -654,7 +654,8 @@ class TabbedBrowser(tabwidget.TabWidget): if self._now_focused and config.val.tabs.mode_on_change == 'restore': current_mode = modeman.instance(self._win_id).mode # only save insert & passthrough mode. otherwise default to normal - if not current_mode in (usertypes.KeyMode.insert,usertypes.KeyMode.passthrough): + input_modes = (usertypes.KeyMode.insert, usertypes.KeyMode.passthrough) + if current_mode not in input_modes: current_mode = usertypes.KeyMode.normal self._now_focused.data.input_mode = current_mode From fecb551c5ee8912d45c89277a0e0d922b6f549b3 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 15 Jan 2018 16:19:38 -0500 Subject: [PATCH 14/19] shorten lines --- qutebrowser/browser/browsertab.py | 2 +- qutebrowser/mainwindow/tabbedbrowser.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index a8ffedc01..e855edac7 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -98,7 +98,7 @@ class TabData: Only used for QtWebKit. pinned: Flag to pin the tab. fullscreen: Whether the tab has a video shown fullscreen currently. - input_mode: current input mode for the tab. (insert, passthrough, normal) + input_mode: current input mode for the tab. """ keep_icon = attr.ib(False) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 617981988..3bd95a8e3 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -654,8 +654,8 @@ class TabbedBrowser(tabwidget.TabWidget): if self._now_focused and config.val.tabs.mode_on_change == 'restore': current_mode = modeman.instance(self._win_id).mode # only save insert & passthrough mode. otherwise default to normal - input_modes = (usertypes.KeyMode.insert, usertypes.KeyMode.passthrough) - if current_mode not in input_modes: + modes = (usertypes.KeyMode.insert, usertypes.KeyMode.passthrough) + if current_mode not in modes: current_mode = usertypes.KeyMode.normal self._now_focused.data.input_mode = current_mode @@ -669,7 +669,8 @@ class TabbedBrowser(tabwidget.TabWidget): for mode in modes_to_leave: modeman.leave(self._win_id, mode, 'tab changed', maybe=True) if config.val.tabs.mode_on_change == 'restore': - modeman.enter(self._win_id, tab.data.input_mode, 'restore input mode for tab') + modeman.enter(self._win_id, tab.data.input_mode, + 'restore input mode for tab') if self._now_focused is not None: objreg.register('last-focused-tab', self._now_focused, update=True, scope='window', window=self._win_id) From a3ce03e0bd8374d63e3d48aff0acf745f9a16eb2 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 9 Feb 2018 10:31:40 -0500 Subject: [PATCH 15/19] address requested changes - syntax cleanup - use attr.ib when declaring class attributes - remove unnecessary comments - code simplification --- qutebrowser/browser/browsertab.py | 2 +- qutebrowser/mainwindow/tabbedbrowser.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qutebrowser/browser/browsertab.py b/qutebrowser/browser/browsertab.py index e855edac7..d73607929 100644 --- a/qutebrowser/browser/browsertab.py +++ b/qutebrowser/browser/browsertab.py @@ -106,7 +106,7 @@ class TabData: override_target = attr.ib(None) pinned = attr.ib(False) fullscreen = attr.ib(False) - input_mode = usertypes.KeyMode.normal + input_mode = attr.ib(usertypes.KeyMode.normal) class AbstractAction: diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 3bd95a8e3..cd9f52b37 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -643,6 +643,9 @@ class TabbedBrowser(tabwidget.TabWidget): @pyqtSlot(int) def on_current_changed(self, idx): """Set last-focused-tab and leave hinting mode when focus changed.""" + mode_on_change = config.val.tabs.mode_on_change + modes_to_save = [usertypes.KeyMode.insert, + usertypes.KeyMode.passthrough] if idx == -1 or self.shutting_down: # closing the last tab (before quitting) or shutting down return @@ -651,11 +654,9 @@ class TabbedBrowser(tabwidget.TabWidget): log.webview.debug("on_current_changed got called with invalid " "index {}".format(idx)) return - if self._now_focused and config.val.tabs.mode_on_change == 'restore': + if self._now_focused is not None and mode_on_change == 'restore': current_mode = modeman.instance(self._win_id).mode - # only save insert & passthrough mode. otherwise default to normal - modes = (usertypes.KeyMode.insert, usertypes.KeyMode.passthrough) - if current_mode not in modes: + if current_mode not in modes_to_save: current_mode = usertypes.KeyMode.normal self._now_focused.data.input_mode = current_mode @@ -663,12 +664,11 @@ class TabbedBrowser(tabwidget.TabWidget): tab.setFocus() modes_to_leave = [usertypes.KeyMode.hint, usertypes.KeyMode.caret] - if not config.val.tabs.mode_on_change == 'persist': - modes_to_leave += [usertypes.KeyMode.insert, - usertypes.KeyMode.passthrough] + if mode_on_change != 'persist': + modes_to_leave += modes_to_save for mode in modes_to_leave: modeman.leave(self._win_id, mode, 'tab changed', maybe=True) - if config.val.tabs.mode_on_change == 'restore': + if mode_on_change == 'restore': modeman.enter(self._win_id, tab.data.input_mode, 'restore input mode for tab') if self._now_focused is not None: From 85dfe5c403b3edd8db05d83ec97b0c09a06ea2d0 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 9 Feb 2018 11:28:21 -0500 Subject: [PATCH 16/19] add special code to migrate tabs.persist_mode_on_change setting to tabs.mode_on_change. --- qutebrowser/config/configfiles.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index 77b5190ce..7b1a26e71 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -180,6 +180,14 @@ class YamlConfig(QObject): log.config.debug("Removing {}".format(name)) del self._values[name] + persist = 'tabs.persist_mode_on_change' + if persist in self._values: + if self._values[persist]: + self._values['tabs.mode_on_change'] = 'persist' + else: + self._values['tabs.mode_on_change'] = 'normal' + del self._values[persist] + def _validate(self): """Make sure all settings exist.""" unknown = set(self._values) - set(configdata.DATA) From 9b7db8ee8a2bdd57cccd2de213a855d36d4da51a Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 9 Feb 2018 14:41:33 -0500 Subject: [PATCH 17/19] Need to mark config as dirty in _handle_migrations() Add tests for tabs.persist_mode_on_change migration --- qutebrowser/config/configfiles.py | 3 +-- tests/unit/config/test_configfiles.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index 7b1a26e71..e19e15695 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -179,14 +179,13 @@ class YamlConfig(QObject): elif name in configdata.MIGRATIONS.deleted: log.config.debug("Removing {}".format(name)) del self._values[name] - persist = 'tabs.persist_mode_on_change' if persist in self._values: if self._values[persist]: self._values['tabs.mode_on_change'] = 'persist' else: self._values['tabs.mode_on_change'] = 'normal' - del self._values[persist] + self.unset(persist) def _validate(self): """Make sure all settings exist.""" diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 8659cf891..116d305d3 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -169,6 +169,30 @@ class TestYaml: assert ' old:' not in lines assert ' new:' not in lines + def test_merge_persist_false(self, monkeypatch, yaml, config_tmpdir): + """Migration of tabs.persist_mode_on_change: False.""" + autoconfig = config_tmpdir / 'autoconfig.yml' + autoconfig.write_text('global:\n tabs.persist_mode_on_change: False', encoding='utf-8') + + yaml.load() + yaml._save() + + lines = autoconfig.read_text('utf-8').splitlines() + assert ' tabs.persist_mode_on_change:' not in lines + assert ' tabs.mode_on_change: normal' in lines + + def test_merge_persist_true(self, monkeypatch, yaml, config_tmpdir): + """Migration of tabs.persist_mode_on_change: True.""" + autoconfig = config_tmpdir / 'autoconfig.yml' + autoconfig.write_text('global:\n tabs.persist_mode_on_change: True', encoding='utf-8') + + yaml.load() + yaml._save() + + lines = autoconfig.read_text('utf-8').splitlines() + assert ' tabs.persist_mode_on_change:' not in lines + assert ' tabs.mode_on_change: persist' in lines + def test_renamed_key_unknown_target(self, monkeypatch, yaml, config_tmpdir): """A key marked as renamed with invalid name should raise an error.""" From 57fe674dc442d8cf8dde9ef077e774c710cf57ea Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 9 Feb 2018 15:22:56 -0500 Subject: [PATCH 18/19] shorten lines --- tests/unit/config/test_configfiles.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 116d305d3..101b883cd 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -172,7 +172,8 @@ class TestYaml: def test_merge_persist_false(self, monkeypatch, yaml, config_tmpdir): """Migration of tabs.persist_mode_on_change: False.""" autoconfig = config_tmpdir / 'autoconfig.yml' - autoconfig.write_text('global:\n tabs.persist_mode_on_change: False', encoding='utf-8') + autoconfig.write_text('global:\n tabs.persist_mode_on_change: False', + encoding='utf-8') yaml.load() yaml._save() @@ -184,7 +185,8 @@ class TestYaml: def test_merge_persist_true(self, monkeypatch, yaml, config_tmpdir): """Migration of tabs.persist_mode_on_change: True.""" autoconfig = config_tmpdir / 'autoconfig.yml' - autoconfig.write_text('global:\n tabs.persist_mode_on_change: True', encoding='utf-8') + autoconfig.write_text('global:\n tabs.persist_mode_on_change: True', + encoding='utf-8') yaml.load() yaml._save() From 504e29c004004a96dd9687afbc21e619689d0828 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 9 Feb 2018 21:25:11 -0500 Subject: [PATCH 19/19] fix configfiles tests - fix test_renamed_key() - fix test_deleted_key() - combine both test_merge_persist tests using @pytest.mark.parametrize - fix _handle_migrations(): mark data dirty for renamed and deleted --- qutebrowser/config/configfiles.py | 4 ++-- tests/unit/config/test_configfiles.py | 32 +++++++++------------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index e19e15695..2220de93d 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -175,10 +175,10 @@ class YamlConfig(QObject): new_name = configdata.MIGRATIONS.renamed[name] log.config.debug("Renaming {} to {}".format(name, new_name)) self._values[new_name] = self._values[name] - del self._values[name] + self.unset(name) elif name in configdata.MIGRATIONS.deleted: log.config.debug("Removing {}".format(name)) - del self._values[name] + self.unset(name) persist = 'tabs.persist_mode_on_change' if persist in self._values: if self._values[persist]: diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 101b883cd..341fad689 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -152,7 +152,7 @@ class TestYaml: yaml._save() lines = autoconfig.read_text('utf-8').splitlines() - assert ' hello:' not in lines + assert ' hello: world' not in lines def test_renamed_key(self, monkeypatch, yaml, config_tmpdir): """A key marked as renamed should be renamed properly.""" @@ -166,34 +166,22 @@ class TestYaml: yaml._save() lines = autoconfig.read_text('utf-8').splitlines() - assert ' old:' not in lines - assert ' new:' not in lines + assert ' old: value' not in lines + assert ' tabs.show: value' in lines - def test_merge_persist_false(self, monkeypatch, yaml, config_tmpdir): - """Migration of tabs.persist_mode_on_change: False.""" + @pytest.mark.parametrize('persist', [True, False]) + def test_merge_persist(self, yaml, config_tmpdir, persist): + """Tests for migration of tabs.persist_mode_on_change.""" autoconfig = config_tmpdir / 'autoconfig.yml' - autoconfig.write_text('global:\n tabs.persist_mode_on_change: False', - encoding='utf-8') - + autoconfig.write_text('global:\n tabs.persist_mode_on_change: {}'. + format(persist), encoding='utf-8') yaml.load() yaml._save() lines = autoconfig.read_text('utf-8').splitlines() + mode = 'persist' if persist else 'normal' assert ' tabs.persist_mode_on_change:' not in lines - assert ' tabs.mode_on_change: normal' in lines - - def test_merge_persist_true(self, monkeypatch, yaml, config_tmpdir): - """Migration of tabs.persist_mode_on_change: True.""" - autoconfig = config_tmpdir / 'autoconfig.yml' - autoconfig.write_text('global:\n tabs.persist_mode_on_change: True', - encoding='utf-8') - - yaml.load() - yaml._save() - - lines = autoconfig.read_text('utf-8').splitlines() - assert ' tabs.persist_mode_on_change:' not in lines - assert ' tabs.mode_on_change: persist' in lines + assert ' tabs.mode_on_change: {}'.format(mode) in lines def test_renamed_key_unknown_target(self, monkeypatch, yaml, config_tmpdir):