Merge pull request #2837 from qutebrowser/zeromax

Fix new completion with web-history-max-items set to 0
This commit is contained in:
Florian Bruhin 2017-07-21 22:19:57 +02:00 committed by GitHub
commit 6873991e2b
5 changed files with 27 additions and 3 deletions

View File

@ -60,6 +60,9 @@ 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')
# HistoryCategory should not be added to the completion in that case.
assert max_items != 0
if max_items < 0:
return ''

View File

@ -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

View File

@ -503,7 +503,7 @@ def data(readonly=False):
"0: no history / -1: unlimited"),
('web-history-max-items',
SettingValue(typ.Int(minval=-1), '-1'),
SettingValue(typ.Int(minval=-1, maxval=MAXVALS['int64']), '-1'),
"How many URLs to show in the web history.\n\n"
"0: no history / -1: unlimited"),

View File

@ -110,6 +110,15 @@ def test_set_pattern(pattern, before, after, model_validator, hist):
('c', 'c', '2017-05-16'),
('a', 'a', '2017-04-16'),
]),
(2 ** 63 - 1, [ # Maximum value sqlite can handle for LIMIT
('a', 'a', '2017-04-16'),
('b', 'b', '2017-06-16'),
('c', 'c', '2017-05-16'),
], [
('b', 'b', '2017-06-16'),
('c', 'c', '2017-05-16'),
('a', 'a', '2017-04-16'),
]),
(2, [
('a', 'a', '2017-04-16'),
('b', 'b', '2017-06-16'),

View File

@ -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()