'Replace and find'

@Slot()
def replace_find(self, focus_replace_text=False, replace_all=False):

    if (self.editor is not None):
        replace_text = to_text_string(self.replace_text.currentText())
        search_text = to_text_string(self.search_text.currentText())
        pattern = (search_text if self.re_button.isChecked() else None)
        case = self.case_button.isChecked()
        first = True
        cursor = None
        while True:
            if first:
                seltxt = to_text_string(self.editor.get_selected_text())
                cmptxt1 = (search_text if case else search_text.lower())
                cmptxt2 = (seltxt if case else seltxt.lower())
                if (not pattern):
                    has_selected = self.editor.has_selected_text()
                    if (has_selected and (cmptxt1 == cmptxt2)):
                        pass
                    elif (not self.find(changed=False, forward=True, rehighlight=False)):
                        break
                elif (len(re.findall(pattern, cmptxt2)) > 0):
                    pass
                elif (not self.find(changed=False, forward=True, rehighlight=False)):
                    break
                first = False
                wrapped = False
                position = self.editor.get_position('cursor')
                position0 = position
                cursor = self.editor.textCursor()
                cursor.beginEditBlock()
            else:
                position1 = self.editor.get_position('cursor')
                if is_position_inf(position1, (((position0 + len(replace_text)) - len(search_text)) + 1)):
                    wrapped = True
                if wrapped:
                    if ((position1 == position) or is_position_sup(position1, position)):
                        break
                if (position1 == position0):
                    break
                position0 = position1
            if (pattern is None):
                cursor.removeSelectedText()
                cursor.insertText(replace_text)
            else:
                seltxt = to_text_string(cursor.selectedText())
                cursor.removeSelectedText()
                cursor.insertText(re.sub(pattern, replace_text, seltxt))
            if self.find_next():
                found_cursor = self.editor.textCursor()
                cursor.setPosition(found_cursor.selectionStart(), QTextCursor.MoveAnchor)
                cursor.setPosition(found_cursor.selectionEnd(), QTextCursor.KeepAnchor)
            else:
                break
            if (not replace_all):
                break
        if (cursor is not None):
            cursor.endEditBlock()
        if focus_replace_text:
            self.replace_text.setFocus()
