diff options
author | Florian Bruhin <me@the-compiler.org> | 2022-01-29 11:35:31 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2022-01-29 11:35:31 +0100 |
commit | 7b92d9b2074c5c664c8f6b6bb4bb55c18a17f47b (patch) | |
tree | d6fb8de1dd3eae3b929cf24c94bde1fbdecd3d11 | |
parent | 438b8b46094890a28db6bac07ff1ae67bbc5ee78 (diff) | |
parent | ef87b5df725efe89cff68f8b4d1f60905a6f4b8f (diff) | |
download | qutebrowser-7b92d9b2074c5c664c8f6b6bb4bb55c18a17f47b.tar.gz qutebrowser-7b92d9b2074c5c664c8f6b6bb4bb55c18a17f47b.zip |
Merge remote-tracking branch 'origin/pr/6972'
-rw-r--r-- | qutebrowser/completion/models/miscmodels.py | 16 | ||||
-rw-r--r-- | tests/unit/completion/test_models.py | 28 |
2 files changed, 40 insertions, 4 deletions
diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index d8ebafb29..77072c720 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -103,17 +103,23 @@ def session(*, info=None): return model -def _tabs(*, win_id_filter=lambda _win_id: True, add_win_id=True): +def _tabs(*, win_id_filter=lambda _win_id: True, add_win_id=True, cur_win_id=None): """Helper to get the completion model for tabs/other_tabs. Args: win_id_filter: A filter function for window IDs to include. Should return True for all included windows. add_win_id: Whether to add the window ID to the completion items. + cur_win_id: Window ID to be passed from info.win_id """ def delete_tab(data): """Close the selected tab.""" - win_id, tab_index = data[0].split('/') + if cur_win_id is None: + win_id, tab_index = data[0].split('/') + else: + win_id = cur_win_id + tab_index = data[0] + tabbed_browser = objreg.get('tabbed-browser', scope='window', window=int(win_id)) tabbed_browser.on_tab_close_requested(int(tab_index) - 1) @@ -177,13 +183,15 @@ def other_tabs(*, info): Used for the tab-take command. """ - return _tabs(win_id_filter=lambda win_id: win_id != info.win_id) + return _tabs( + win_id_filter=lambda win_id: win_id != info.win_id, + cur_win_id=info.win_id) def tab_focus(*, info): """A model to complete on open tabs in the current window.""" model = _tabs(win_id_filter=lambda win_id: win_id == info.win_id, - add_win_id=False) + add_win_id=False, cur_win_id=info.win_id) special = [ ("last", "Focus the last-focused tab"), diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 9e6743083..b94c19a06 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -867,6 +867,34 @@ def test_tab_completion_delete(qtmodeltester, fake_web_tab, win_registry, QUrl('https://duckduckgo.com')] +def test_tab_focus_completion_delete(qtmodeltester, fake_web_tab, win_registry, + tabbed_browser_stubs, info): + """Verify closing a tab by deleting it from the completion widget.""" + tabbed_browser_stubs[0].widget.tabs = [ + fake_web_tab(QUrl('https://github.com'), 'GitHub', 0), + fake_web_tab(QUrl('https://wikipedia.org'), 'Wikipedia', 1), + fake_web_tab(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 2) + ] + tabbed_browser_stubs[1].widget.tabs = [ + fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0), + ] + model = miscmodels.tab_focus(info=info) + model.set_pattern('') + qtmodeltester.check(model) + + parent = model.index(0, 0) + idx = model.index(1, 0, parent) + + # # sanity checks + assert model.data(parent) == "Tabs" + assert model.data(idx) == '2' + + model.delete_cur_item(idx) + actual = [tab.url() for tab in tabbed_browser_stubs[0].widget.tabs] + assert actual == [QUrl('https://github.com'), + QUrl('https://duckduckgo.com')] + + def test_tab_completion_not_sorted(qtmodeltester, fake_web_tab, win_registry, tabbed_browser_stubs): """Ensure that the completion row order is the same as tab index order. |