[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [konversation/1.4] src/viewer: Improve removing newlines in the paste editor.
From:       Juan Carlos Torres <carlosdgtorres () gmail ! com>
Date:       2012-07-31 7:35:38
Message-ID: 20120731073538.4CD60A6094 () git ! kde ! org
[Download RAW message or body]

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::MoveAnchor))
-    {
-        cursor.deletePreviousChar();
+    int i = 0;
 
-        if (!cursor.atBlockEnd())
+    while (i < text.length())
+    {
+        if (text[i] == '\n')
         {
-            bool moved = cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor);
-
-            if (moved)
+            if (text[i - 1].category() == QChar::Separator_Space)
             {
-                cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
-
-                if (!cursor.selectedText().contains(' '))
-                {
-                    cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor);
-                    cursor.insertText(" ");
-                }
+                text.remove(i, 1);
+                continue;
             }
+            else
+                text[i] = ' ';
         }
+
+        ++i;
     }
 
-    cursor.endEditBlock();
+    QTextCursor cursor(m_textEditor->document());
+    cursor.select(QTextCursor::Document);
+    cursor.insertText(text);
 }
 
 void PasteEditor::setText(const QString& text)

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic