From 1b879faf84b9ac06ccb1b03fa6ce9527116c4b1e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 11 Mar 2015 07:42:12 +0100 Subject: [PATCH] completion: Highlight text case-insensitively. See #531. --- qutebrowser/completion/completiondelegate.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qutebrowser/completion/completiondelegate.py b/qutebrowser/completion/completiondelegate.py index d88c86c19..03caa5158 100644 --- a/qutebrowser/completion/completiondelegate.py +++ b/qutebrowser/completion/completiondelegate.py @@ -22,7 +22,9 @@ We use this to be able to highlight parts of the text. """ +import re import html + from PyQt5.QtWidgets import QStyle, QStyleOptionViewItem, QStyledItemDelegate from PyQt5.QtCore import QRectF, QSize, Qt from PyQt5.QtGui import (QIcon, QPalette, QTextDocument, QTextOption, @@ -195,9 +197,9 @@ class CompletionItemDelegate(QStyledItemDelegate): if index.parent().isValid(): pattern = index.model().pattern if index.column() == 0 and pattern: - text = self._opt.text.replace( - pattern, - '{}'.format(pattern)) + repl = r'\g<0>' + text = re.sub(re.escape(pattern), repl, self._opt.text, + flags=re.IGNORECASE) self._doc.setHtml(text) else: self._doc.setPlainText(self._opt.text)