From fd07c571e5ea77beb7c19ecf593cb26a9913ac5b Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Thu, 29 Jun 2017 20:54:56 -0400 Subject: [PATCH] Store pattern in completion view, not model. The pattern property is used for highlighting. It is purely display-related, so it should be in the view rather than the model. --- qutebrowser/completion/completiondelegate.py | 3 ++- qutebrowser/completion/completionwidget.py | 3 +++ qutebrowser/completion/models/completionmodel.py | 4 ---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qutebrowser/completion/completiondelegate.py b/qutebrowser/completion/completiondelegate.py index 5813d6dcb..b2a933cef 100644 --- a/qutebrowser/completion/completiondelegate.py +++ b/qutebrowser/completion/completiondelegate.py @@ -196,7 +196,8 @@ class CompletionItemDelegate(QStyledItemDelegate): self._doc.setDocumentMargin(2) if index.parent().isValid(): - pattern = index.model().pattern + view = self.parent() + pattern = view.pattern columns_to_filter = index.model().columns_to_filter(index) if index.column() in columns_to_filter and pattern: repl = r'\g<0>' diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index 415968131..9b8d31ad6 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -40,6 +40,7 @@ class CompletionView(QTreeView): headers, and children show as flat list. Attributes: + pattern: Current filter pattern, used for highlighting. _win_id: The ID of the window this CompletionView is associated with. _height: The height to use for the CompletionView. _height_perc: Either None or a percentage if height should be relative. @@ -106,6 +107,7 @@ class CompletionView(QTreeView): def __init__(self, win_id, parent=None): super().__init__(parent) + self.pattern = '' self._win_id = win_id # FIXME handle new aliases. # objreg.get('config').changed.connect(self.init_command_completion) @@ -288,6 +290,7 @@ class CompletionView(QTreeView): self.expand(model.index(i, 0)) def set_pattern(self, pattern): + self.pattern = pattern with debug.log_time(log.completion, 'Set pattern {}'.format(pattern)): self.model().set_pattern(pattern) self._resize_columns() diff --git a/qutebrowser/completion/models/completionmodel.py b/qutebrowser/completion/models/completionmodel.py index 55b0546d9..9eb57fe88 100644 --- a/qutebrowser/completion/models/completionmodel.py +++ b/qutebrowser/completion/models/completionmodel.py @@ -35,7 +35,6 @@ class CompletionModel(QAbstractItemModel): Attributes: column_widths: The width percentages of the columns used in the completion view. - pattern: Current filter pattern, used for highlighting. _categories: The sub-categories. """ @@ -43,7 +42,6 @@ class CompletionModel(QAbstractItemModel): super().__init__(parent) self.column_widths = column_widths self._categories = [] - self.pattern = '' def _cat_from_idx(self, index): """Return the category pointed to by the given index. @@ -180,8 +178,6 @@ class CompletionModel(QAbstractItemModel): pattern: The filter pattern to set. """ log.completion.debug("Setting completion pattern '{}'".format(pattern)) - # TODO: should pattern be saved in the view layer instead? - self.pattern = pattern for cat in self._categories: cat.set_pattern(pattern)