diff --git a/qutebrowser/models/basecompletion.py b/qutebrowser/models/basecompletion.py index 5f7c73358..49e3f5b97 100644 --- a/qutebrowser/models/basecompletion.py +++ b/qutebrowser/models/basecompletion.py @@ -68,19 +68,16 @@ class BaseCompletionModel(QStandardItemModel): marks.append((pos1, pos2)) return marks - def mark_all_items(self, needle): - """Mark a string in all items (children of root-children). + def mark_item(self, index, needle): + """Mark a string in the givem item. Args: + index: A QModelIndex of the item to mark. needle: The string to mark. """ - for i in range(self.rowCount()): - cat = self.index(i, 0) - for k in range(self.rowCount(cat)): - idx = self.index(k, 0, cat) - old = self.data(idx) - marks = self._get_marks(needle, old) - self.setData(idx, marks, ROLE_MARKS) + haystack = self.data(index) + marks = self._get_marks(needle, haystack) + self.setData(index, marks, ROLE_MARKS) def new_category(self, name): """Add a new category to the model. diff --git a/qutebrowser/models/completionfilter.py b/qutebrowser/models/completionfilter.py index 648194c8a..4bf33ed42 100644 --- a/qutebrowser/models/completionfilter.py +++ b/qutebrowser/models/completionfilter.py @@ -95,6 +95,14 @@ class CompletionFilterModel(QSortFilterProxyModel): count += self.rowCount(cat) return count + def mark_all_items(self, text): + """Mark the given text in all visible items.""" + for i in range(self.rowCount()): + cat = self.index(i, 0) + for k in range(self.rowCount(cat)): + index = self.mapToSource(self.index(k, 0, cat)) + self.srcmodel.mark_item(index, text) + def setSourceModel(self, model): """Override QSortFilterProxyModel's setSourceModel to clear pattern.""" logger.debug("Setting source model: {}".format(model)) diff --git a/qutebrowser/widgets/_completion.py b/qutebrowser/widgets/_completion.py index 56d677d5f..37d6c3211 100644 --- a/qutebrowser/widgets/_completion.py +++ b/qutebrowser/widgets/_completion.py @@ -329,7 +329,7 @@ class CompletionView(QTreeView): pattern = parts[cursor_part] if parts else '' logger.debug("pattern: {}".format(pattern)) self._model.pattern = pattern - self._model.srcmodel.mark_all_items(pattern) + self._model.mark_all_items(pattern) if self._enabled: self.show()