Skip to content

Commit

Permalink
Fixed completion highlighting.
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Jul 13, 2015
1 parent 523cb45 commit d4c91f7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
12 changes: 8 additions & 4 deletions qutebrowser/completion/completiondelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,14 @@ def _get_textdoc(self, index):

if index.parent().isValid():
pattern = index.model().pattern
repl = r'<span class="highlight">\g<0></span>'
text = re.sub(re.escape(pattern), repl, self._opt.text,
flags=re.IGNORECASE)
self._doc.setHtml(text)
if(index.column() in index.model().srcmodel.columns_to_highlight
and pattern):
repl = r'<span class="highlight">\g<0></span>'
text = re.sub(re.escape(pattern), repl, self._opt.text,
flags=re.IGNORECASE)
self._doc.setHtml(text)
else:
self._doc.setPlainText(self._opt.text)
else:
self._doc.setHtml('<b>{}</b>'.format(html.escape(self._opt.text)))

Expand Down
1 change: 1 addition & 0 deletions qutebrowser/completion/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BaseCompletionModel(QStandardItemModel):
def __init__(self, parent=None):
super().__init__(parent)
self.setColumnCount(3)
self.columns_to_highlight = []

def new_category(self, name, sort=None):
"""Add a new category to the model.
Expand Down
3 changes: 3 additions & 0 deletions qutebrowser/completion/models/configmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SettingSectionCompletionModel(base.BaseCompletionModel):

def __init__(self, parent=None):
super().__init__(parent)
self.columns_to_highlight.append(0)
cat = self.new_category("Sections")
for name in configdata.DATA.keys():
desc = configdata.SECTION_DESC[name].splitlines()[0].strip()
Expand All @@ -53,6 +54,7 @@ class SettingOptionCompletionModel(base.BaseCompletionModel):

def __init__(self, section, parent=None):
super().__init__(parent)
self.columns_to_highlight.append(0)
cat = self.new_category(section)
sectdata = configdata.DATA[section]
self._misc_items = {}
Expand Down Expand Up @@ -106,6 +108,7 @@ class SettingValueCompletionModel(base.BaseCompletionModel):

def __init__(self, section, option, parent=None):
super().__init__(parent)
self.columns_to_highlight.append(0)
self._section = section
self._option = option
objreg.get('config').changed.connect(self.update_current_value)
Expand Down
5 changes: 5 additions & 0 deletions qutebrowser/completion/models/miscmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CommandCompletionModel(base.BaseCompletionModel):

def __init__(self, parent=None):
super().__init__(parent)
self.columns_to_highlight.append(0)
assert cmdutils.cmd_dict
cmdlist = []
for obj in set(cmdutils.cmd_dict.values()):
Expand All @@ -56,6 +57,7 @@ class HelpCompletionModel(base.BaseCompletionModel):

def __init__(self, parent=None):
super().__init__(parent)
self.columns_to_highlight.append(0)
self._init_commands()
self._init_settings()

Expand Down Expand Up @@ -98,6 +100,7 @@ class QuickmarkCompletionModel(base.BaseCompletionModel):

def __init__(self, match_field='url', parent=None):
super().__init__(parent)
self.columns_to_highlight.append(0)
cat = self.new_category("Quickmarks")
quickmarks = objreg.get('quickmark-manager').marks.items()
if match_field == 'url':
Expand All @@ -119,6 +122,7 @@ class BookmarkCompletionModel(base.BaseCompletionModel):

def __init__(self, match_field='url', parent=None):
super().__init__(parent)
self.columns_to_highlight.append(0)
cat = self.new_category("Bookmarks")
bookmarks = objreg.get('bookmark-manager').bookmarks.items()
if match_field == 'url':
Expand All @@ -140,6 +144,7 @@ class SessionCompletionModel(base.BaseCompletionModel):

def __init__(self, parent=None):
super().__init__(parent)
self.columns_to_highlight.append(0)
cat = self.new_category("Sessions")
try:
for name in objreg.get('session-manager').list_sessions():
Expand Down
3 changes: 3 additions & 0 deletions qutebrowser/completion/models/urlmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class UrlCompletionModel(base.BaseCompletionModel):
def __init__(self, parent=None):
super().__init__(parent)

self.columns_to_highlight.append(0)
self.columns_to_highlight.append(1)

self._quickmark_cat = self.new_category("Quickmarks")
self._bookmark_cat = self.new_category("Bookmarks")
self._history_cat = self.new_category("History")
Expand Down

0 comments on commit d4c91f7

Please sign in to comment.