'Replace and find in the current selection'

@Slot()
def replace_find_selection(self, focus_replace_text=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()
        words = self.words_button.isChecked()
        re_flags = (re.MULTILINE if case else (re.IGNORECASE | re.MULTILINE))
        cursor = self.editor.textCursor()
        cursor.beginEditBlock()
        seltxt = to_text_string(self.editor.get_selected_text())
        if (not pattern):
            pattern = re.escape(search_text)
            replace_text = re.escape(replace_text)
        if words:
            try:
                re.compile(pattern)
            except re.error:
                return
            word_pattern = '\\b{pattern}\\b'.format(pattern=pattern)
            replacement = re.sub(word_pattern, replace_text, seltxt, flags=re_flags)
        else:
            replacement = re.sub(pattern, replace_text, seltxt, flags=re_flags)
        if (replacement != seltxt):
            cursor.removeSelectedText()
            cursor.insertText(replacement)
        cursor.endEditBlock()
        if focus_replace_text:
            self.replace_text.setFocus()
        else:
            self.editor.setFocus()
