diff options
Diffstat (limited to 'objects/basetexteditor.cpp')
-rw-r--r-- | objects/basetexteditor.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/objects/basetexteditor.cpp b/objects/basetexteditor.cpp index 58a427c..8f62091 100644 --- a/objects/basetexteditor.cpp +++ b/objects/basetexteditor.cpp @@ -486,16 +486,7 @@ bool BaseTextEditor::findRegexp(const QString ®exp, bool backward, bool caseS void BaseTextEditor::deleteRegion(const Position &from, const Position &to) { - QPointer<Mark> start = createMark(); - gotoPosition(from); - int fromPos = nativePosition(); - gotoPosition(to); - int toPos = nativePosition(); - QTextCursor cursor( textEditorWidget()->document()); - cursor.setPosition(fromPos); - cursor.setPosition(toPos, QTextCursor::KeepAnchor); - cursor.removeSelectedText(); - gotoMark(start); + fetchSelectionAndDelete(from, to, true); } void BaseTextEditor::gotoDocumentStart() @@ -516,6 +507,23 @@ int BaseTextEditor::lineCount() return 0; } +QString BaseTextEditor::fetchSelectionAndDelete(const Position &from, const Position &to, bool del) +{ + QPointer<Mark> start = createMark(); + gotoPosition(from); + int fromPos = nativePosition(); + gotoPosition(to); + int toPos = nativePosition(); + QTextCursor cursor( textEditorWidget()->document()); + cursor.setPosition(fromPos); + cursor.setPosition(toPos, QTextCursor::KeepAnchor); + QString text = cursor.selectedText(); + if (del) + cursor.removeSelectedText(); + gotoMark(start); + return text; +} + void BaseTextEditor::indent() { if (textEditorWidget()) @@ -543,3 +551,9 @@ QTextDocument::FindFlags BaseTextEditor::flags(bool backward, bool caseSensitive return textEditor->editorWidget(); return 0; } + + +QString Scripting::Internal::BaseTextEditor::text(const Scripting::Internal::Position &from, const Scripting::Internal::Position &to) +{ + return fetchSelectionAndDelete(from, to, false); +} |