Join user state of removed text blocks

Note: Indentation of surrounding code was fixed.

Done-with: mae
(cherry picked from commit 8d3d3381c127f0f4dd9fc507c3069acddbf40535)
Change-Id: I8d3d3381c127f0f4dd9fc507c3069acddbf40535
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
This commit is contained in:
Leandro Melo 2011-08-12 18:45:42 +02:00 committed by Qt by Nokia
parent 402a8c036b
commit 85a14abd2e
2 changed files with 28 additions and 9 deletions

View File

@ -531,16 +531,17 @@ int QTextDocumentPrivate::remove_block(int pos, int *blockFormat, int command, Q
Q_ASSERT(b);
if (blocks.size(b) == 1 && command == QTextUndoCommand::BlockAdded) {
Q_ASSERT((int)blocks.position(b) == pos);
// qDebug("removing empty block");
// empty block remove the block itself
Q_ASSERT((int)blocks.position(b) == pos);
// qDebug("removing empty block");
// empty block remove the block itself
} else {
// non empty block, merge with next one into this block
// qDebug("merging block with next");
int n = blocks.next(b);
Q_ASSERT((int)blocks.position(n) == pos + 1);
blocks.setSize(b, blocks.size(b) + blocks.size(n) - 1);
b = n;
// non empty block, merge with next one into this block
// qDebug("merging block with next");
int n = blocks.next(b);
Q_ASSERT((int)blocks.position(n) == pos + 1);
blocks.setSize(b, blocks.size(b) + blocks.size(n) - 1);
blocks.fragment(b)->userState = blocks.fragment(n)->userState;
b = n;
}
*blockFormat = blocks.fragment(b)->format;

View File

@ -50,6 +50,7 @@
#include <qabstracttextdocumentlayout.h>
#include <qtextlayout.h>
#include <qtextcursor.h>
#include <qtextobject.h>
#include <qdebug.h>
QT_FORWARD_DECLARE_CLASS(QTextDocument)
@ -152,6 +153,8 @@ private slots:
void cursorPositionWithBlockUndoAndRedo2();
void cursorPositionWithBlockUndoAndRedo3();
void joinNonEmptyRemovedBlockUserState();
private:
int blockCount();
@ -1976,5 +1979,20 @@ void tst_QTextCursor::cursorPositionWithBlockUndoAndRedo3()
QCOMPARE(cursor.position(), cursorPositionBefore);
}
void tst_QTextCursor::joinNonEmptyRemovedBlockUserState()
{
cursor.insertText("Hello");
cursor.insertBlock();
cursor.insertText("World");
cursor.block().setUserState(10);
cursor.movePosition(QTextCursor::EndOfBlock);
cursor.movePosition(QTextCursor::PreviousBlock, QTextCursor::KeepAnchor);
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
cursor.removeSelectedText();
QCOMPARE(cursor.block().userState(), 10);
}
QTEST_MAIN(tst_QTextCursor)
#include "tst_qtextcursor.moc"