diff --git a/toxygen/list_items.py b/toxygen/list_items.py
index 90f7ed9..5a62cb6 100644
--- a/toxygen/list_items.py
+++ b/toxygen/list_items.py
@@ -194,9 +194,26 @@ class MessageItem(QtGui.QWidget):
tmp = self.message.toHtml()
strings = re.findall(text, tmp, flags=re.IGNORECASE)
for s in strings:
- tmp = tmp.replace(s, '{}'.format(s))
+ tmp = self.replace_all(tmp, s)
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 = '{}'.format(substring)
+ text = text[:i] + sub + text[i + l:]
+ i += len(sub)
+ return text
+
class ContactItem(QtGui.QWidget):
"""
diff --git a/toxygen/mainscreen_widgets.py b/toxygen/mainscreen_widgets.py
index 6ad086c..1910cb7 100644
--- a/toxygen/mainscreen_widgets.py
+++ b/toxygen/mainscreen_widgets.py
@@ -465,6 +465,10 @@ class SearchScreen(QtGui.QWidget):
self.search_text.setPlaceholderText(QtGui.QApplication.translate("MainWindow", "Search", None,
QtGui.QApplication.UnicodeUTF8))
+ def show(self):
+ super().show()
+ self.search_text.setFocus()
+
def search(self):
Profile.get_instance().update()
text = self.search_text.text()