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) override_target = attr.ib(None)
pinned = attr.ib(False) pinned = attr.ib(False)
fullscreen = attr.ib(False) fullscreen = attr.ib(False)
input_mode = usertypes.KeyMode.normal input_mode = attr.ib(usertypes.KeyMode.normal)
class AbstractAction: class AbstractAction:

View File

@ -643,6 +643,9 @@ class TabbedBrowser(tabwidget.TabWidget):
@pyqtSlot(int) @pyqtSlot(int)
def on_current_changed(self, idx): def on_current_changed(self, idx):
"""Set last-focused-tab and leave hinting mode when focus changed.""" """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: if idx == -1 or self.shutting_down:
# closing the last tab (before quitting) or shutting down # closing the last tab (before quitting) or shutting down
return return
@ -651,11 +654,9 @@ class TabbedBrowser(tabwidget.TabWidget):
log.webview.debug("on_current_changed got called with invalid " log.webview.debug("on_current_changed got called with invalid "
"index {}".format(idx)) "index {}".format(idx))
return 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 current_mode = modeman.instance(self._win_id).mode
# only save insert & passthrough mode. otherwise default to normal if current_mode not in modes_to_save:
modes = (usertypes.KeyMode.insert, usertypes.KeyMode.passthrough)
if current_mode not in modes:
current_mode = usertypes.KeyMode.normal current_mode = usertypes.KeyMode.normal
self._now_focused.data.input_mode = current_mode self._now_focused.data.input_mode = current_mode
@ -663,12 +664,11 @@ class TabbedBrowser(tabwidget.TabWidget):
tab.setFocus() tab.setFocus()
modes_to_leave = [usertypes.KeyMode.hint, usertypes.KeyMode.caret] modes_to_leave = [usertypes.KeyMode.hint, usertypes.KeyMode.caret]
if not config.val.tabs.mode_on_change == 'persist': if mode_on_change != 'persist':
modes_to_leave += [usertypes.KeyMode.insert, modes_to_leave += modes_to_save
usertypes.KeyMode.passthrough]
for mode in modes_to_leave: for mode in modes_to_leave:
modeman.leave(self._win_id, mode, 'tab changed', maybe=True) 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, modeman.enter(self._win_id, tab.data.input_mode,
'restore input mode for tab') 'restore input mode for tab')
if self._now_focused is not None: if self._now_focused is not None: