address requested changes

- syntax cleanup
- use attr.ib when declaring class attributes
- remove unnecessary comments
- code simplification
This commit is contained in:
Marc Jauvin 2018-02-09 10:31:40 -05:00
parent fecb551c5e
commit a3ce03e0bd
2 changed files with 9 additions and 9 deletions

View File

@ -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:

View File

@ -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: