diff options
author | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-12-30 19:28:02 +0000 |
---|---|---|
committer | ubbo <ubbo@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2010-12-30 19:28:02 +0000 |
commit | 110ddb4d9ec4d3126113b466efc687830e39053a (patch) | |
tree | f482a18bdddc77655d0b801b15c09180b27ef771 /textedit.cpp | |
parent | corrected behaviour of confirmation dialog on key import (diff) | |
download | gpg4usb-110ddb4d9ec4d3126113b466efc687830e39053a.tar.gz gpg4usb-110ddb4d9ec4d3126113b466efc687830e39053a.zip |
make quote undoable
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@414 34ebc366-c3a9-4b3c-9f84-69acf7962910
Diffstat (limited to 'textedit.cpp')
-rw-r--r-- | textedit.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/textedit.cpp b/textedit.cpp index da55681..202c3e8 100644 --- a/textedit.cpp +++ b/textedit.cpp @@ -31,10 +31,21 @@ void TextEdit::dropEvent(QDropEvent* event) void TextEdit::quote() { - QString text=this->toPlainText(); - text.replace("\n","\n> ",Qt::CaseSensitive); - text.insert(0,QString("> ")); - this->setPlainText(text); + + QTextCursor cursor(this->document()); + + // beginEditBlock and endEditBlock() let operation look like single undo/redo operation + cursor.beginEditBlock(); + cursor.setPosition(0); + cursor.insertText("> "); + while (!cursor.isNull() && !cursor.atEnd()) { + cursor.movePosition(QTextCursor::EndOfLine); + cursor.movePosition(QTextCursor::NextCharacter); + if(!cursor.atEnd()) + cursor.insertText("> "); + } + cursor.endEditBlock(); + } bool TextEdit::isKey(QString key) |