Merge remote-tracking branch 'origin/pr/3577'

This commit is contained in:
Florian Bruhin 2018-02-10 11:40:49 +01:00
commit c7133a662c
6 changed files with 62 additions and 19 deletions

View File

@ -242,7 +242,7 @@
|<<tabs.new_position.related,tabs.new_position.related>>|Position of new tabs opened from another tab.
|<<tabs.new_position.unrelated,tabs.new_position.unrelated>>|Position of new tabs which aren't opened from another tab.
|<<tabs.padding,tabs.padding>>|Padding (in pixels) around text for tabs.
|<<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>>|Set input mode behavior when switching tab.
|<<tabs.pinned.shrink,tabs.pinned.shrink>>|Shrink pinned tabs down to their contents.
|<<tabs.position,tabs.position>>|Position of the tab bar.
|<<tabs.select_on_remove,tabs.select_on_remove>>|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: <<types,Bool>>
Type: <<types,String>>
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

View File

@ -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.
"""
keep_icon = attr.ib(False)
@ -105,6 +106,7 @@ class TabData:
override_target = attr.ib(None)
pinned = attr.ib(False)
fullscreen = attr.ib(False)
input_mode = attr.ib(usertypes.KeyMode.normal)
class AbstractAction:

View File

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

View File

@ -175,10 +175,17 @@ 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]:
self._values['tabs.mode_on_change'] = 'persist'
else:
self._values['tabs.mode_on_change'] = 'normal'
self.unset(persist)
def _validate(self):
"""Make sure all settings exist."""

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,17 +654,23 @@ class TabbedBrowser(tabwidget.TabWidget):
log.webview.debug("on_current_changed got called with invalid "
"index {}".format(idx))
return
if self._now_focused is not None and mode_on_change == 'restore':
current_mode = modeman.instance(self._win_id).mode
if current_mode not in modes_to_save:
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:
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 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)

View File

@ -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,8 +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
@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: {}'.
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: {}'.format(mode) in lines
def test_renamed_key_unknown_target(self, monkeypatch, yaml,
config_tmpdir):