From e90e5569c9c1860068e35b765bacbc8bda4d8b45 Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Tue, 17 Dec 2019 00:06:56 +0700 Subject: Add new behavior for tabs_are_windows setting * Window ID (category labels) are removed from completion --- qutebrowser/completion/models/miscmodels.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index a6d2b3b32..04947523d 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -21,7 +21,7 @@ import typing -from qutebrowser.config import configdata +from qutebrowser.config import configdata, config from qutebrowser.utils import objreg, log from qutebrowser.completion.models import completionmodel, listcategory, util @@ -112,6 +112,10 @@ def _buffer(skip_win_id=None): model = completionmodel.CompletionModel(column_widths=(6, 40, 54)) + # abbreviate tabs_are_windows for convenience + taw = True if config.val.tabs.tabs_are_windows else False + if taw: windows = [] + for win_id in objreg.window_registry: if skip_win_id is not None and win_id == skip_win_id: continue @@ -122,13 +126,24 @@ def _buffer(skip_win_id=None): tabs = [] for idx in range(tabbed_browser.widget.count()): tab = tabbed_browser.widget.widget(idx) - tabs.append(("{}/{}".format(win_id, idx + 1), + label = ("{}".format(win_id + 1) if taw + else "{}/{}".format(win_id, idx + 1)) + tabs.append((label, tab.url().toDisplayString(), tabbed_browser.widget.page_title(idx))) cat = listcategory.ListCategory( str(win_id), tabs, delete_func=delete_buffer, sort=False) + if taw: + windows += tabs + continue model.add_category(cat) + # add the single list category of windows to the model + if taw: + win = listcategory.ListCategory( + "Windows", windows, delete_func=delete_buffer, sort=False) + model.add_category(win) + return model -- cgit v1.2.3-54-g00ecf From 7e8a1f0e206715d1b2741109651dbf281bad92f2 Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Tue, 17 Dec 2019 01:26:28 +0700 Subject: Make changes based on review * also some minor style/comment mods --- qutebrowser/completion/models/miscmodels.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index 04947523d..c1fc06958 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -21,7 +21,7 @@ import typing -from qutebrowser.config import configdata, config +from qutebrowser.config import config, configdata from qutebrowser.utils import objreg, log from qutebrowser.completion.models import completionmodel, listcategory, util @@ -112,9 +112,8 @@ def _buffer(skip_win_id=None): model = completionmodel.CompletionModel(column_widths=(6, 40, 54)) - # abbreviate tabs_are_windows for convenience - taw = True if config.val.tabs.tabs_are_windows else False - if taw: windows = [] + tabs_are_windows = config.val.tabs.tabs_are_windows + windows = [] # list storing single-tab windows when tabs_are_windows for win_id in objreg.window_registry: if skip_win_id is not None and win_id == skip_win_id: @@ -126,20 +125,18 @@ def _buffer(skip_win_id=None): tabs = [] for idx in range(tabbed_browser.widget.count()): tab = tabbed_browser.widget.widget(idx) - label = ("{}".format(win_id + 1) if taw - else "{}/{}".format(win_id, idx + 1)) - tabs.append((label, - tab.url().toDisplayString(), + label = (str(win_id + 1) if tabs_are_windows + else "{}/{}".format(win_id, idx + 1)) + tabs.append((label, tab.url().toDisplayString(), tabbed_browser.widget.page_title(idx))) - cat = listcategory.ListCategory( - str(win_id), tabs, delete_func=delete_buffer, sort=False) - if taw: + if tabs_are_windows: windows += tabs - continue - model.add_category(cat) + else: + cat = listcategory.ListCategory( + str(win_id), tabs, delete_func=delete_buffer, sort=False) + model.add_category(cat) - # add the single list category of windows to the model - if taw: + if tabs_are_windows: win = listcategory.ListCategory( "Windows", windows, delete_func=delete_buffer, sort=False) model.add_category(win) -- cgit v1.2.3-54-g00ecf From 1c7fb675501ccc52d4f39870074d49fbbe64608f Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Wed, 18 Dec 2019 00:56:41 +0700 Subject: Add buffer resolution cond for tabs_are_windows --- qutebrowser/browser/commands.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 871d0f673..b59cb6d26 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -848,6 +848,8 @@ class CommandDispatcher: if len(index_parts) == 2: win_id = int(index_parts[0]) idx = int(index_parts[1]) + elif len(index_parts) == 1 and config.val.tabs.tabs_are_windows: + win_id, idx = int(index_parts[0]) - 1, 1 elif len(index_parts) == 1: idx = int(index_parts[0]) active_win = QApplication.activeWindow() -- cgit v1.2.3-54-g00ecf From 228abd179a9242b77771d9af8d51be3d3180a1e3 Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Wed, 18 Dec 2019 01:01:25 +0700 Subject: Prevent `:tab-take` when using tabs_are_windows currently, `tab_take` results in 2nd instance of the taken tab to be opened as a new window, without the old win/tab getting closed, since `tabbed_browser.close_tab` does not close the last tab of a window --- qutebrowser/browser/commands.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index b59cb6d26..706fa40ed 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -434,6 +434,10 @@ class CommandDispatcher: in which case the closest match will be taken. keep: If given, keep the old tab around. """ + if config.val.tabs.tabs_are_windows: + raise cmdutils.CommandError("Can't take tabs when using " + "windows as tabs") + tabbed_browser, tab = self._resolve_buffer_index(index) if tabbed_browser is self._tabbed_browser: -- cgit v1.2.3-54-g00ecf From 61ea2010577a13032821445d34ad6ea4316ec17d Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Wed, 18 Dec 2019 03:01:44 +0700 Subject: Minor grammar fix --- qutebrowser/browser/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 706fa40ed..54933631a 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -1239,7 +1239,7 @@ class CommandDispatcher: def toggle_inspector(self): """Toggle the web inspector. - Note: Due a bug in Qt, the inspector will show incorrect request + Note: Due to a bug in Qt, the inspector will show incorrect request headers in the network tab. """ tab = self._current_widget() -- cgit v1.2.3-54-g00ecf From 2ff7a96c32fdcee42bda40fa9a8088a8b509c663 Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Wed, 18 Dec 2019 13:50:01 +0700 Subject: Fix: keep tab number in completion for buffer --- qutebrowser/browser/commands.py | 2 -- qutebrowser/completion/models/miscmodels.py | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 54933631a..f4cabaccd 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -852,8 +852,6 @@ class CommandDispatcher: if len(index_parts) == 2: win_id = int(index_parts[0]) idx = int(index_parts[1]) - elif len(index_parts) == 1 and config.val.tabs.tabs_are_windows: - win_id, idx = int(index_parts[0]) - 1, 1 elif len(index_parts) == 1: idx = int(index_parts[0]) active_win = QApplication.activeWindow() diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index c1fc06958..fad9290dd 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -125,9 +125,8 @@ def _buffer(skip_win_id=None): tabs = [] for idx in range(tabbed_browser.widget.count()): tab = tabbed_browser.widget.widget(idx) - label = (str(win_id + 1) if tabs_are_windows - else "{}/{}".format(win_id, idx + 1)) - tabs.append((label, tab.url().toDisplayString(), + tabs.append(("{}/{}".format(win_id, idx + 1), + tab.url().toDisplayString(), tabbed_browser.widget.page_title(idx))) if tabs_are_windows: windows += tabs -- cgit v1.2.3-54-g00ecf From e96c5a0e76d72236b9ec1a88f8dce3dfe711a390 Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Thu, 19 Dec 2019 02:17:35 +0700 Subject: Add type annotation * add to `windows` & `tabs` inside _`buffer` function --- qutebrowser/completion/models/miscmodels.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index fad9290dd..8c6f3ce11 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -113,7 +113,8 @@ def _buffer(skip_win_id=None): model = completionmodel.CompletionModel(column_widths=(6, 40, 54)) tabs_are_windows = config.val.tabs.tabs_are_windows - windows = [] # list storing single-tab windows when tabs_are_windows + # list storing all single-tabbed windows when tabs_are_windows + windows = [] # type: typing.List[typing.Tuple[str, str, str]] for win_id in objreg.window_registry: if skip_win_id is not None and win_id == skip_win_id: @@ -122,7 +123,7 @@ def _buffer(skip_win_id=None): window=win_id) if tabbed_browser.shutting_down: continue - tabs = [] + tabs = [] # type: typing.List[typing.Tuple[str, str, str]] for idx in range(tabbed_browser.widget.count()): tab = tabbed_browser.widget.widget(idx) tabs.append(("{}/{}".format(win_id, idx + 1), -- cgit v1.2.3-54-g00ecf From 5ad409fa3160f0b45005c61e26b85dd54de87c1b Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Fri, 20 Dec 2019 00:03:07 +0700 Subject: Add test for completion model under tabs_are_windows --- tests/unit/completion/test_models.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index cdba937b2..ad4db043e 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -758,6 +758,36 @@ def test_tab_completion_not_sorted(qtmodeltester, fake_web_tab, win_registry, }) +def test_tab_completion_tabs_are_windows(qtmodeltester, fake_web_tab, + win_registry, tabbed_browser_stubs, + config_stub): + """Verify tabs across all windows are listed under a single category.""" + config_stub.val.tabs.tabs.tabs_are_windows = True + + tabbed_browser_stubs[0].widget.tabs = [ + fake_web_tab(QUrl('https://github.com'), 'GitHub', 0), + fake_web_tab(QUrl('https://wikipedia.org'), 'Wikipedia', 1), + ] + tabbed_browser_stubs[1].widget.tabs = [ + fake_web_tab(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 0), + ] + tabbed_browser_stubs[2].widget.tabs = [ + fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0), + ] + model = miscmodels.buffer() + model.set_pattern('') + qtmodeltester.check(model) + + _check_completions(model, { + 'Windows': [ + ('0/1', 'https://github.com', 'GitHub'), + ('0/2', 'https://wikipedia.org', 'Wikipedia'), + ('1/1', 'https://duckduckgo.com', 'DuckDuckGo'), + ('2/1', 'https://wiki.archlinux.org', 'ArchWiki'), + ] + }) + + def test_other_buffer_completion(qtmodeltester, fake_web_tab, win_registry, tabbed_browser_stubs, info): tabbed_browser_stubs[0].widget.tabs = [ -- cgit v1.2.3-54-g00ecf From 88a8c919ac5e1ad327ea8bab1d0b391af6c441be Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Fri, 20 Dec 2019 00:34:33 +0700 Subject: Add test scenario * for `:tab-take` under tabs_are_windows --- tests/end2end/features/tabs.feature | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature index 485ab771a..747e6c19a 100644 --- a/tests/end2end/features/tabs.feature +++ b/tests/end2end/features/tabs.feature @@ -1204,6 +1204,14 @@ Feature: Tab management And I run :tab-take 0/1 Then the error "Can't take a tab from the same window" should be shown + Scenario: Take a tab while using tabs_are_windows + Given I have a fresh instance + When I open data/numbers/1.txt + And I open data/numbers/2.txt in a new window + And I set tabs.tabs_are_windows to true + And I run :tab-take 0/1 + Then the error "Can't take tabs when using windows as tabs" should be shown + # :tab-give @xfail_norun # Needs qutewm -- cgit v1.2.3-54-g00ecf From acb633318ef723f04f488be722b575190836045f Mon Sep 17 00:00:00 2001 From: Jethro Cao Date: Fri, 20 Dec 2019 01:07:56 +0700 Subject: Fix errors for test_tab_completion_tabs_are_windows --- tests/unit/completion/test_models.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index ad4db043e..00875a9a0 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -762,18 +762,16 @@ def test_tab_completion_tabs_are_windows(qtmodeltester, fake_web_tab, win_registry, tabbed_browser_stubs, config_stub): """Verify tabs across all windows are listed under a single category.""" - config_stub.val.tabs.tabs.tabs_are_windows = True - 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://duckduckgo.com'), 'DuckDuckGo', 0), - ] - tabbed_browser_stubs[2].widget.tabs = [ fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0), ] + + config_stub.val.tabs.tabs_are_windows = True model = miscmodels.buffer() model.set_pattern('') qtmodeltester.check(model) @@ -782,8 +780,8 @@ def test_tab_completion_tabs_are_windows(qtmodeltester, fake_web_tab, 'Windows': [ ('0/1', 'https://github.com', 'GitHub'), ('0/2', 'https://wikipedia.org', 'Wikipedia'), - ('1/1', 'https://duckduckgo.com', 'DuckDuckGo'), - ('2/1', 'https://wiki.archlinux.org', 'ArchWiki'), + ('0/3', 'https://duckduckgo.com', 'DuckDuckGo'), + ('1/1', 'https://wiki.archlinux.org', 'ArchWiki'), ] }) -- cgit v1.2.3-54-g00ecf