fixed bug with html in search and focus

This commit is contained in:
ingvar1995 2017-02-12 22:49:08 +03:00
parent 508db0acea
commit 150942446d
2 changed files with 22 additions and 1 deletions

View File

@ -194,9 +194,26 @@ class MessageItem(QtGui.QWidget):
tmp = self.message.toHtml() tmp = self.message.toHtml()
strings = re.findall(text, tmp, flags=re.IGNORECASE) strings = re.findall(text, tmp, flags=re.IGNORECASE)
for s in strings: for s in strings:
tmp = tmp.replace(s, '<font color="red">{}</font>'.format(s)) tmp = self.replace_all(tmp, s)
self.message.setHtml(tmp) self.message.setHtml(tmp)
@staticmethod
def replace_all(text, substring):
i, l = 0, len(substring)
while i < len(text) - l + 1:
index = text[i:].find(substring)
if index == -1:
break
i += index
lgt, rgt = text[i:].find('<'), text[i:].find('>')
if rgt < lgt:
i += rgt + 1
continue
sub = '<font color="red">{}</font>'.format(substring)
text = text[:i] + sub + text[i + l:]
i += len(sub)
return text
class ContactItem(QtGui.QWidget): class ContactItem(QtGui.QWidget):
""" """

View File

@ -465,6 +465,10 @@ class SearchScreen(QtGui.QWidget):
self.search_text.setPlaceholderText(QtGui.QApplication.translate("MainWindow", "Search", None, self.search_text.setPlaceholderText(QtGui.QApplication.translate("MainWindow", "Search", None,
QtGui.QApplication.UnicodeUTF8)) QtGui.QApplication.UnicodeUTF8))
def show(self):
super().show()
self.search_text.setFocus()
def search(self): def search(self):
Profile.get_instance().update() Profile.get_instance().update()
text = self.search_text.text() text = self.search_text.text()