# Buggy code
def find_text(
    self, text, changed=True, forward=True, case=False, words=False, regexp=False
):
    """Find text"""
    cursor = self.textCursor()
    findflag = QTextDocument.FindFlag()
    if not forward:
        findflag = findflag | QTextDocument.FindBackward
    if case:
        findflag = findflag | QTextDocument.FindCaseSensitively
    moves = [QTextCursor.NoMove]
    if forward:
        moves += [QTextCursor.NextWord, QTextCursor.Start]
        if changed:
            if to_text_string(cursor.selectedText()):
                new_position = min([cursor.selectionStart(), cursor.selectionEnd()])
                cursor.setPosition(new_position)
            else:
                cursor.movePosition(QTextCursor.PreviousWord)
    else:
        moves += [QTextCursor.End]
    if not regexp:
        text = re.escape(to_text_string(text))
    if QT55_VERSION:
        pattern = QRegularExpression(r"\b{}\b".format(text) if words else text)
        if case:
            pattern.setPatternOptions(QRegularExpression.CaseInsensitiveOption)
    else:
        pattern = QRegExp(
            r"\b{}\b".format(text) if words else text,
            Qt.CaseSensitive if case else Qt.CaseInsensitive,
            QRegExp.RegExp2,
        )

    for move in moves:
        cursor.movePosition(move)
        if regexp and "\\n" in text:
            # Multiline regular expression
            found_cursor = self.find_multiline_pattern(pattern, cursor, findflag)
        else:
            # Single line find: using the QTextDocument's find function,
            # probably much more efficient than ours
            found_cursor = self.document().find(pattern, cursor, findflag)
        if found_cursor is not None and not found_cursor.isNull():
            self.setTextCursor(found_cursor)
            return True
    return False


# Traceback (UnicodeEncodeError)
File "/home/dmitry.makarevich/anaconda3/envs/py2/lib/python2.7/site-packages/spyder/widgets/findreplace.py", line 368, in text_has_been_edited
self.find(changed=True, forward=True, start_highlight_timer=True)
File "/home/dmitry.makarevich/anaconda3/envs/py2/lib/python2.7/site-packages/spyder/widgets/findreplace.py", line 416, in find
words=words, regexp=regexp)
File "/home/dmitry.makarevich/anaconda3/envs/py2/lib/python2.7/site-packages/spyder/widgets/mixins.py", line 497, in find_text
pattern = QRegularExpression(r"\b{}\b".format(text) if words else
UnicodeEncodeError: 'ascii' codec can't encode character u'\u044b' in position 1: ordinal not in range(128)

# Fixed code
def find_text(
    self, text, changed=True, forward=True, case=False, words=False, regexp=False
):
    """Find text"""
    cursor = self.textCursor()
    findflag = QTextDocument.FindFlag()

    if not forward:
        findflag = findflag | QTextDocument.FindBackward

    if case:
        findflag = findflag | QTextDocument.FindCaseSensitively

    moves = [QTextCursor.NoMove]
    if forward:
        moves += [QTextCursor.NextWord, QTextCursor.Start]
        if changed:
            if to_text_string(cursor.selectedText()):
                new_position = min([cursor.selectionStart(), cursor.selectionEnd()])
                cursor.setPosition(new_position)
            else:
                cursor.movePosition(QTextCursor.PreviousWord)
    else:
        moves += [QTextCursor.End]

    if regexp:
        text = to_text_string(text)
    else:
        text = re.escape(to_text_string(text))

    if QT55_VERSION:
        pattern = QRegularExpression("\\b{}\\b".format(text) if words else text)
        if case:
            pattern.setPatternOptions(QRegularExpression.CaseInsensitiveOption)
    else:
        pattern = QRegExp(
            "\\b{}\\b".format(text) if words else text,
            Qt.CaseSensitive if case else Qt.CaseInsensitive,
            QRegExp.RegExp2,
        )

    for move in moves:
        cursor.movePosition(move)
        if regexp and "\\n" in text:
            # Multiline regular expression
            found_cursor = self.find_multiline_pattern(pattern, cursor, findflag)
        else:
            # Single line find: using the QTextDocument's find function,
            # probably much more efficient than ours
            found_cursor = self.document().find(pattern, cursor, findflag)
        if found_cursor is not None and not found_cursor.isNull():
            self.setTextCursor(found_cursor)
            return True

    return False