From 1917911dd8bf7eab68b0d1979dc783b67361a51f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 20 Oct 2014 07:13:29 +0200 Subject: [PATCH] Don't set marks data if the pattern is empty. See #190. --- qutebrowser/models/completionfilter.py | 20 +++++++++++--------- qutebrowser/widgets/completiondelegate.py | 5 ++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/qutebrowser/models/completionfilter.py b/qutebrowser/models/completionfilter.py index 4e0f6549a..fd9603f64 100644 --- a/qutebrowser/models/completionfilter.py +++ b/qutebrowser/models/completionfilter.py @@ -34,7 +34,7 @@ class CompletionFilterModel(QSortFilterProxyModel): """Subclass of QSortFilterProxyModel with custom sorting/filtering. Attributes: - _pattern: The pattern to filter with. + pattern: The pattern to filter with. srcmodel: The current source model. Kept as attribute because calling `sourceModel` takes quite a long time for some reason. @@ -44,7 +44,7 @@ class CompletionFilterModel(QSortFilterProxyModel): super().__init__(parent) super().setSourceModel(source) self.srcmodel = source - self._pattern = '' + self.pattern = '' def set_pattern(self, val): """Setter for pattern. @@ -57,7 +57,7 @@ class CompletionFilterModel(QSortFilterProxyModel): Args: val: The value to set. """ - self._pattern = val + self.pattern = val self.invalidate() sortcol = 0 try: @@ -102,6 +102,8 @@ class CompletionFilterModel(QSortFilterProxyModel): def mark_all_items(self, text): """Mark the given text in all visible items.""" + if not text: + return for i in range(self.rowCount()): cat = self.index(i, 0) qtutils.ensure_valid(cat) @@ -129,7 +131,7 @@ class CompletionFilterModel(QSortFilterProxyModel): parent: The parent item QModelIndex. Return: - True if self._pattern is contained in item, or if it's a root item + True if self.pattern is contained in item, or if it's a root item (category). False in all other cases """ if parent == QModelIndex(): @@ -138,14 +140,14 @@ class CompletionFilterModel(QSortFilterProxyModel): qtutils.ensure_valid(idx) data = self.srcmodel.data(idx) # TODO more sophisticated filtering - if not self._pattern: + if not self.pattern: return True - return self._pattern.casefold() in data.casefold() + return self.pattern.casefold() in data.casefold() def lessThan(self, lindex, rindex): """Custom sorting implementation. - Prefers all items which start with self._pattern. Other than that, uses + Prefers all items which start with self.pattern. Other than that, uses normal Python string sorting. Args: @@ -167,8 +169,8 @@ class CompletionFilterModel(QSortFilterProxyModel): left = self.srcmodel.data(lindex) right = self.srcmodel.data(rindex) - leftstart = left.startswith(self._pattern) - rightstart = right.startswith(self._pattern) + leftstart = left.startswith(self.pattern) + rightstart = right.startswith(self.pattern) if leftstart and rightstart: return left < right diff --git a/qutebrowser/widgets/completiondelegate.py b/qutebrowser/widgets/completiondelegate.py index 2dce69d6e..025d58afc 100644 --- a/qutebrowser/widgets/completiondelegate.py +++ b/qutebrowser/widgets/completiondelegate.py @@ -197,7 +197,10 @@ class CompletionItemDelegate(QStyledItemDelegate): """)) self._doc.setDocumentMargin(2) - if index.column() == 0: + if index.column() == 0 and index.model().pattern: + # We take a shortcut here by not checking anything if the models + # pattern is empty. This is required because the marks data is + # invalid in that case (for performance reasons). marks = index.data(basecompletion.Role.marks) if marks is None: return