From 544094ba722ad3c9b2ee53977d55cdf4805cc00f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 21 Jul 2017 17:55:47 +0200 Subject: [PATCH] Use simpler way of preventing History completion --- qutebrowser/completion/models/histcategory.py | 12 +++++++----- qutebrowser/completion/models/urlmodel.py | 6 ++++-- tests/unit/completion/test_histcategory.py | 7 +------ tests/unit/completion/test_models.py | 10 ++++++++++ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/qutebrowser/completion/models/histcategory.py b/qutebrowser/completion/models/histcategory.py index c87ba026c..612eb0bf4 100644 --- a/qutebrowser/completion/models/histcategory.py +++ b/qutebrowser/completion/models/histcategory.py @@ -60,7 +60,10 @@ class HistoryCategory(QSqlQueryModel): def _atime_expr(self): """If max_items is set, return an expression to limit the query.""" max_items = config.get('completion', 'web-history-max-items') - if max_items <= 0: + # HistoryCategory should not be added to the completion in that case. + assert max_items != 0 + + if max_items < 0: return '' min_atime = sql.Query(' '.join([ @@ -83,10 +86,9 @@ class HistoryCategory(QSqlQueryModel): # treat spaces as wildcards to match any of the typed words pattern = re.sub(r' +', '%', pattern) pattern = '%{}%'.format(pattern) - if config.get('completion', 'web-history-max-items') != 0: - with debug.log_time('sql', 'Running completion query'): - self._query.run(pat=pattern) - self.setQuery(self._query) + with debug.log_time('sql', 'Running completion query'): + self._query.run(pat=pattern) + self.setQuery(self._query) def delete_cur_item(self, index): """Delete the row at the given index.""" diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 0c5fbeacc..fbb9661ec 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -22,6 +22,7 @@ from qutebrowser.completion.models import (completionmodel, listcategory, histcategory) from qutebrowser.utils import log, objreg +from qutebrowser.config import config _URLCOL = 0 @@ -65,6 +66,7 @@ def url(): model.add_category(listcategory.ListCategory( 'Bookmarks', bookmarks, delete_func=_delete_bookmark)) - hist_cat = histcategory.HistoryCategory(delete_func=_delete_history) - model.add_category(hist_cat) + if config.get('completion', 'web-history-max-items') != 0: + hist_cat = histcategory.HistoryCategory(delete_func=_delete_history) + model.add_category(hist_cat) return model diff --git a/tests/unit/completion/test_histcategory.py b/tests/unit/completion/test_histcategory.py index bfd9d4aa5..0b5fcb915 100644 --- a/tests/unit/completion/test_histcategory.py +++ b/tests/unit/completion/test_histcategory.py @@ -117,12 +117,7 @@ def test_set_pattern(pattern, before, after, model_validator, hist): ], [ ('b', 'b', '2017-06-16'), ('c', 'c', '2017-05-16'), - ]), - (0, [ - ('a', 'a', '2017-04-16'), - ('b', 'b', '2017-06-16'), - ('c', 'c', '2017-05-16'), - ], []), + ]) ]) def test_sorting(max_items, before, after, model_validator, hist, config_stub): """Validate the filtering and sorting results of set_pattern.""" diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index 5b632eb3a..83c3d3e7d 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -396,6 +396,16 @@ def test_url_completion_delete_history(qtmodeltester, assert 'https://python.org' not in web_history_populated +def test_url_completion_zero_limit(config_stub, web_history, quickmarks, + bookmarks): + """Make sure there's no history if the limit was set to zero.""" + config_stub.data['completion']['web-history-max-items'] = 0 + model = urlmodel.url() + model.set_pattern('') + category = model.index(2, 0) # "History" normally + assert model.data(category) is None + + def test_session_completion(qtmodeltester, session_manager_stub): session_manager_stub.sessions = ['default', '1', '2'] model = miscmodels.session()