Use simpler way of preventing History completion
This commit is contained in:
parent
6660297871
commit
544094ba72
@ -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."""
|
||||
|
@ -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
|
||||
|
@ -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."""
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user