diff options
author | mae <qt-info@nokia.com> | 2009-05-08 14:39:42 (GMT) |
---|---|---|
committer | mae <qt-info@nokia.com> | 2009-05-08 14:42:51 (GMT) |
commit | 4af30f47c37fd0e6826aca2984dd0f567dc7e465 (patch) | |
tree | a06a574de77a49c0e87ffabd46533a38386aee85 /src/gui/text/qtextcursor.cpp | |
parent | da1234d6ea6c5e3c0b84d64fbe9ac15a7c3f30d3 (diff) | |
download | Qt-4af30f47c37fd0e6826aca2984dd0f567dc7e465.zip Qt-4af30f47c37fd0e6826aca2984dd0f567dc7e465.tar.gz Qt-4af30f47c37fd0e6826aca2984dd0f567dc7e465.tar.bz2 |
Fixed unwanted merging of undo commands from different edit blocks
With this patch, commands no longer merge across block bounderies.
In order to have merging still work for the normal insertion and deletion
case, the unnecessary beginEditBlock()/endEditBlock() calls where
cleaned up.
Reviewed-by: Simon Hausmann
Diffstat (limited to 'src/gui/text/qtextcursor.cpp')
-rw-r--r-- | src/gui/text/qtextcursor.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp index 48963bb..d12e3fe 100644 --- a/src/gui/text/qtextcursor.cpp +++ b/src/gui/text/qtextcursor.cpp @@ -145,7 +145,6 @@ void QTextCursorPrivate::remove() { if (anchor == position) return; - priv->beginEditBlock(); currentCharFormat = -1; int pos1 = position; int pos2 = adjusted_anchor; @@ -159,15 +158,18 @@ void QTextCursorPrivate::remove() // deleting inside table? -> delete only content QTextTable *table = complexSelectionTable(); if (table) { + priv->beginEditBlock(); int startRow, startCol, numRows, numCols; selectedTableCells(&startRow, &numRows, &startCol, &numCols); clearCells(table, startRow, startCol, numRows, numCols, op); + adjusted_anchor = anchor = position; + priv->endEditBlock(); } else { priv->remove(pos1, pos2-pos1, op); + adjusted_anchor = anchor = position; + priv->finishEdit(); } - adjusted_anchor = anchor = position; - priv->endEditBlock(); } void QTextCursorPrivate::clearCells(QTextTable *table, int startRow, int startCol, int numRows, int numCols, QTextUndoCommand::Operation op) @@ -1291,9 +1293,14 @@ void QTextCursor::insertText(const QString &text, const QTextCharFormat &_format QTextCharFormat format = _format; format.clearProperty(QTextFormat::ObjectIndex); - d->priv->beginEditBlock(); + bool hasEditBlock = false; + + if (d->anchor != d->position) { + hasEditBlock = true; + d->priv->beginEditBlock(); + d->remove(); + } - d->remove(); if (!text.isEmpty()) { QTextFormatCollection *formats = d->priv->formatCollection(); int formatIdx = formats->indexForFormat(format); @@ -1323,6 +1330,11 @@ void QTextCursor::insertText(const QString &text, const QTextCharFormat &_format || ch == QChar::ParagraphSeparator || ch == QLatin1Char('\r')) { + if (!hasEditBlock) { + hasEditBlock = true; + d->priv->beginEditBlock(); + } + if (blockEnd > blockStart) d->priv->insert(d->position, textStart + blockStart, blockEnd - blockStart, formatIdx); @@ -1333,7 +1345,8 @@ void QTextCursor::insertText(const QString &text, const QTextCharFormat &_format if (textStart + blockStart < textEnd) d->priv->insert(d->position, textStart + blockStart, textEnd - textStart - blockStart, formatIdx); } - d->priv->endEditBlock(); + if (hasEditBlock) + d->priv->endEditBlock(); d->setX(); } |