completion: Highlight text case-insensitively.

See #531.
This commit is contained in:
Florian Bruhin 2015-03-11 07:42:12 +01:00
parent 5b4f6d39c2
commit 1b879faf84

View File

@ -22,7 +22,9 @@
We use this to be able to highlight parts of the text. We use this to be able to highlight parts of the text.
""" """
import re
import html import html
from PyQt5.QtWidgets import QStyle, QStyleOptionViewItem, QStyledItemDelegate from PyQt5.QtWidgets import QStyle, QStyleOptionViewItem, QStyledItemDelegate
from PyQt5.QtCore import QRectF, QSize, Qt from PyQt5.QtCore import QRectF, QSize, Qt
from PyQt5.QtGui import (QIcon, QPalette, QTextDocument, QTextOption, from PyQt5.QtGui import (QIcon, QPalette, QTextDocument, QTextOption,
@ -195,9 +197,9 @@ class CompletionItemDelegate(QStyledItemDelegate):
if index.parent().isValid(): if index.parent().isValid():
pattern = index.model().pattern pattern = index.model().pattern
if index.column() == 0 and pattern: if index.column() == 0 and pattern:
text = self._opt.text.replace( repl = r'<span class="highlight">\g<0></span>'
pattern, text = re.sub(re.escape(pattern), repl, self._opt.text,
'<span class="highlight">{}</span>'.format(pattern)) flags=re.IGNORECASE)
self._doc.setHtml(text) self._doc.setHtml(text)
else: else:
self._doc.setPlainText(self._opt.text) self._doc.setPlainText(self._opt.text)