Git commit 2efd75d044aeb889c1a0da56e7b46a3b7d557ef9 by Juan Carlos Torres. Committed on 31/07/2012 at 09:18. Pushed by jucato into branch '1.4'. Improve removing newlines in the paste editor. * Switch to using simpler QString methods instead of QTextCursor manipulation. * Explicitly handle Windows carriage return character. * Recognize preceding whitespace other than 0x20. M +17 -17 src/viewer/pasteeditor.cpp http://commits.kde.org/konversation/2efd75d044aeb889c1a0da56e7b46a3b7d557ef9 diff --git a/src/viewer/pasteeditor.cpp b/src/viewer/pasteeditor.cpp index 80a9eae..4a12e2b 100644 --- a/src/viewer/pasteeditor.cpp +++ b/src/viewer/pasteeditor.cpp @@ -69,31 +69,31 @@ void PasteEditor::addQuotationIndicators() = void PasteEditor::removeNewlines() { - QTextCursor cursor(m_textEditor->document()); - cursor.beginEditBlock(); + QString text(m_textEditor->toPlainText()); + text.remove('\r'); + text.remove(QRegExp("^\n+|\n+$")); = - while(cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnc= hor)) - { - cursor.deletePreviousChar(); + int i =3D 0; = - if (!cursor.atBlockEnd()) + while (i < text.length()) + { + if (text[i] =3D=3D '\n') { - bool moved =3D cursor.movePosition(QTextCursor::Left, QTextCur= sor::MoveAnchor); - - if (moved) + if (text[i - 1].category() =3D=3D QChar::Separator_Space) { - cursor.movePosition(QTextCursor::Right, QTextCursor::KeepA= nchor, 2); - - if (!cursor.selectedText().contains(' ')) - { - cursor.movePosition(QTextCursor::Left, QTextCursor::Mo= veAnchor); - cursor.insertText(" "); - } + text.remove(i, 1); + continue; } + else + text[i] =3D ' '; } + + ++i; } = - cursor.endEditBlock(); + QTextCursor cursor(m_textEditor->document()); + cursor.select(QTextCursor::Document); + cursor.insertText(text); } = void PasteEditor::setText(const QString& text)