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

List:       kde-commits
Subject:    KDE/kdelibs/kate
From:       Christoph Cullmann <cullmann () kde ! org>
Date:       2010-07-06 18:31:17
Message-ID: 20100706183118.019EEAC85D () svn ! kde ! org
[Download RAW message or body]

SVN commit 1146830 by cullmann:

fix insertText with stringlist, please backport to 4.5

 M  +2 -84     document/katedocument.cpp  
 M  +1 -1      tests/katedocument_test.cpp  


--- trunk/KDE/kdelibs/kate/document/katedocument.cpp #1146829:1146830
@@ -658,91 +658,10 @@
   if (!isReadWrite())
     return false;
 
-  if (textLines.isEmpty() || (textLines.count() == 1 && \
                textLines.first().isEmpty()))
-    return true;
-
-  // FIXME - huh, contradicted below
-  if (position.line() > lines())
-    return false;
-
-  editStart();
-
-  if (position.line() > lines())
-    editInsertLine(position.line(),QString());
-
-  int currentLine = position.line();
-  int insertColumn = position.column();
-
-  bool replacetabs = ( config()->replaceTabsDyn() );
-  int tabWidth = config()->tabWidth();
-
-  static const QChar newLineChar('\n');
-  static const QChar tabChar('\t');
-  static const QChar spaceChar(' ');
-
-  int insertColumnExpanded = insertColumn;
-  Kate::TextLine l = kateTextLine( currentLine );
-  if (l)
-    insertColumnExpanded = l->toVirtualColumn( insertColumn, tabWidth );
-
-  foreach (const QString &text, textLines)
-  {
-    int pos = 0;
-    int currentLineStart = 0;
-    for (; pos < text.length(); pos++)
-    {
-      const QChar& ch = text.at(pos);
-
-      if (ch == newLineChar)
-      {
-        // Only perform the text insert if there is text to insert
-        if (currentLineStart < pos)
-          editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - \
                currentLineStart));
-
-        if ( !block )
-        {
-          editWrapLine(currentLine, pos + insertColumn - currentLineStart);
-          insertColumn = 0;
+  // just reuse normal function
+  return insertText (position, textLines.join ("\n"), block);
         }
-        else
-        {
-          if ( currentLine == lastLine() )
-            editWrapLine(currentLine , insertColumn + pos - currentLineStart);
-          insertColumn = position.column(); // tab expansion might change this
-        }
 
-        currentLine++;
-        currentLineStart = pos + 1;
-        l = kateTextLine( currentLine );
-        if (l)
-          insertColumnExpanded = l->toVirtualColumn( insertColumn, tabWidth );
-      }
-      else
-      {
-        if ( replacetabs && ch == tabChar )
-        {
-          int spacesRequired = tabWidth - ( (insertColumnExpanded + pos - \
                currentLineStart) % tabWidth );
-          editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - \
                currentLineStart) + QString(spacesRequired, spaceChar));
-
-          insertColumn += pos - currentLineStart + spacesRequired;
-          l = kateTextLine( currentLine );
-          if (l)
-            insertColumnExpanded = l->toVirtualColumn( insertColumn, tabWidth );
-          currentLineStart = pos + 1;
-        }
-      }
-    }
-
-    // Only perform the text insert if there is text to insert
-    if (currentLineStart < pos - currentLineStart)
-      editInsertText(currentLine, insertColumn, text.mid(currentLineStart, pos - \
                currentLineStart));
-  }
-
-  editEnd();
-  return true;
-}
-
-
 bool KateDocument::removeText ( const KTextEditor::Range &_range, bool block )
 {
   KTextEditor::Range range = _range;
@@ -833,7 +752,6 @@
 
   bool success = true;
   foreach (const QString &string, text)
-    // FIXME assumes no \n in each string
     success &= editInsertLine (line++, string);
 
   return success;
--- trunk/KDE/kdelibs/kate/tests/katedocument_test.cpp #1146829:1146830
@@ -90,7 +90,7 @@
                 "foo\n"
                 "foo\n"
                 "bar\n");
-    doc.replaceText( Range(1, 0, 3, 0), QStringList() << "new\n" << "text\n", false \
); +    doc.replaceText( Range(1, 0, 3, 0), QStringList() << "new" << "text" << "", \
false );  QCOMPARE(doc.text(), QString("asdf\n"
                                  "new\n"
                                  "text\n"


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

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