From a3ce03e0bd8374d63e3d48aff0acf745f9a16eb2 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 9 Feb 2018 10:31:40 -0500 Subject: [PATCH] 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: