From b6dcd4d3872f6706a899af92f35690a7ac4ed5a7 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 28 Nov 2017 07:20:49 -0500 Subject: [PATCH] Reapply "Hide quickmark/bookmark completion if empty." This reverts commit e72e8b8556561c74eb5700c7e800aa0838f30a4c. Now that the SQL category works in isolation, it is possible to hide quickmarks/bookmarks when those categories are empty. Fixes #960 --- qutebrowser/completion/models/urlmodel.py | 15 +++++--- tests/unit/completion/test_models.py | 46 ++++++++++++++++++++++- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 617fa74b5..1d7a075eb 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -56,14 +56,17 @@ def url(*, info): """ model = completionmodel.CompletionModel(column_widths=(40, 50, 10)) - quickmarks = ((url, name) for (name, url) - in objreg.get('quickmark-manager').marks.items()) + quickmarks = [(url, name) for (name, url) + in objreg.get('quickmark-manager').marks.items()] bookmarks = objreg.get('bookmark-manager').marks.items() - model.add_category(listcategory.ListCategory( - 'Quickmarks', quickmarks, delete_func=_delete_quickmark, sort=False)) - model.add_category(listcategory.ListCategory( - 'Bookmarks', bookmarks, delete_func=_delete_bookmark, sort=False)) + if quickmarks: + model.add_category(listcategory.ListCategory( + 'Quickmarks', quickmarks, delete_func=_delete_quickmark, + sort=False)) + if bookmarks: + model.add_category(listcategory.ListCategory( + 'Bookmarks', bookmarks, delete_func=_delete_bookmark, sort=False)) if info.config.get('completion.web_history_max_items') != 0: hist_cat = histcategory.HistoryCategory(delete_func=_delete_history) diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 5276ffd2a..1481ec47a 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -356,6 +356,50 @@ def test_url_completion(qtmodeltester, web_history_populated, }) +def test_url_completion_no_quickmarks(qtmodeltester, web_history_populated, + quickmark_manager_stub, bookmarks, info): + """Test that the quickmark category is gone with no quickmarks.""" + model = urlmodel.url(info=info) + model.set_pattern('') + qtmodeltester.data_display_may_return_none = True + qtmodeltester.check(model) + + _check_completions(model, { + "Bookmarks": [ + ('https://github.com', 'GitHub', None), + ('https://python.org', 'Welcome to Python.org', None), + ('http://qutebrowser.org', 'qutebrowser | qutebrowser', None), + ], + "History": [ + ('https://github.com', 'https://github.com', '2016-05-01'), + ('https://python.org', 'Welcome to Python.org', '2016-03-08'), + ('http://qutebrowser.org', 'qutebrowser', '2015-09-05'), + ], + }) + + +def test_url_completion_no_bookmarks(qtmodeltester, web_history_populated, + quickmarks, bookmark_manager_stub, info): + """Test that the bookmarks category is gone with no bookmarks.""" + model = urlmodel.url(info=info) + model.set_pattern('') + qtmodeltester.data_display_may_return_none = True + qtmodeltester.check(model) + + _check_completions(model, { + "Quickmarks": [ + ('https://wiki.archlinux.org', 'aw', None), + ('https://wikipedia.org', 'wiki', None), + ('https://duckduckgo.com', 'ddg', None), + ], + "History": [ + ('https://github.com', 'https://github.com', '2016-05-01'), + ('https://python.org', 'Welcome to Python.org', '2016-03-08'), + ('http://qutebrowser.org', 'qutebrowser', '2015-09-05'), + ], + }) + + @pytest.mark.parametrize('url, title, pattern, rowcount', [ ('example.com', 'Site Title', '', 1), ('example.com', 'Site Title', 'ex', 1), @@ -382,7 +426,7 @@ def test_url_completion_pattern(web_history, quickmark_manager_stub, model = urlmodel.url(info=info) model.set_pattern(pattern) # 2, 0 is History - assert model.rowCount(model.index(2, 0)) == rowcount + assert model.rowCount(model.index(0, 0)) == rowcount def test_url_completion_delete_bookmark(qtmodeltester, bookmarks,