From 3f6f03e3250194672f8aa87c8973238d6d382797 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 14 Feb 2017 09:06:42 -0500 Subject: [PATCH] Respect web-history-max-items with SQL. Use a LIMIT with the sql competion model to limit history entries as the old completion implementation did. --- qutebrowser/completion/models/urlmodel.py | 4 +++- tests/unit/completion/test_models.py | 6 ++---- tests/unit/completion/test_sqlmodel.py | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 1390fff21..b844fa93e 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -20,6 +20,7 @@ """Function to return the url completion model for the `open` command.""" from qutebrowser.completion.models import sqlmodel +from qutebrowser.config import config def url(): @@ -32,7 +33,8 @@ def url(): model = sqlmodel.SqlCompletionModel(column_widths=(40, 50, 10), columns_to_filter=[urlcol, textcol]) - model.new_category('History') + model.new_category('History', + limit=config.get('completion', 'web-history-max-items')) model.new_category('Quickmarks') model.new_category('Bookmarks') return model diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index a89041713..91ac8286f 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -268,8 +268,8 @@ def test_url_completion(qtmodeltester, config_stub, web_history, quickmarks, - the most recent entries are included """ # TODO: time formatting and item limiting - #config_stub.data['completion'] = {'timestamp-format': '%Y-%m-%d', - # 'web-history-max-items': 2} + config_stub.data['completion'] = {'timestamp-format': '%Y-%m-%d', + 'web-history-max-items': 2} model = urlmodel.url() qtmodeltester.data_display_may_return_none = True qtmodeltester.check(model) @@ -303,8 +303,6 @@ def test_url_completion(qtmodeltester, config_stub, web_history, quickmarks, datetime(2015, 9, 5).timestamp()), ('https://python.org', 'Welcome to Python.org', datetime(2016, 3, 8).timestamp()), - ('https://github.com', 'https://github.com', - datetime(2016, 5, 1).timestamp()), ], }) diff --git a/tests/unit/completion/test_sqlmodel.py b/tests/unit/completion/test_sqlmodel.py index 2c158d3d4..1044a831f 100644 --- a/tests/unit/completion/test_sqlmodel.py +++ b/tests/unit/completion/test_sqlmodel.py @@ -202,6 +202,7 @@ def test_first_last_item(data, first, last): assert model.data(model.first_item()) == first assert model.data(model.last_item()) == last + def test_limit(): table = sql.SqlTable('test_limit', ['a'], primary_key='a') for i in range(5):