summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextdocument_p.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/text/qtextdocument_p.cpp')
-rw-r--r--src/gui/text/qtextdocument_p.cpp51
1 files changed, 33 insertions, 18 deletions
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp
index f3cd481..7b3f985 100644
--- a/src/gui/text/qtextdocument_p.cpp
+++ b/src/gui/text/qtextdocument_p.cpp
@@ -205,6 +205,7 @@ QTextDocumentPrivate::QTextDocumentPrivate()
undoEnabled = true;
inContentsChange = false;
+ blockCursorAdjustment = false;
defaultTextOption.setTabStop(80); // same as in qtextengine.cpp
defaultTextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
@@ -234,17 +235,17 @@ void QTextDocumentPrivate::init()
void QTextDocumentPrivate::clear()
{
Q_Q(QTextDocument);
- for (int i = 0; i < cursors.count(); ++i) {
- cursors.at(i)->setPosition(0);
- cursors.at(i)->currentCharFormat = -1;
- cursors.at(i)->anchor = 0;
- cursors.at(i)->adjusted_anchor = 0;
+
+ foreach (QTextCursorPrivate *curs, cursors) {
+ curs->setPosition(0);
+ curs->currentCharFormat = -1;
+ curs->anchor = 0;
+ curs->adjusted_anchor = 0;
}
QList<QTextCursorPrivate *>oldCursors = cursors;
QT_TRY{
cursors.clear();
- changedCursors.clear();
QMap<int, QTextObject *>::Iterator objectIt = objects.begin();
while (objectIt != objects.end()) {
@@ -287,8 +288,8 @@ void QTextDocumentPrivate::clear()
QTextDocumentPrivate::~QTextDocumentPrivate()
{
- for (int i = 0; i < cursors.count(); ++i)
- cursors.at(i)->priv = 0;
+ foreach (QTextCursorPrivate *curs, cursors)
+ curs->priv = 0;
cursors.clear();
undoState = 0;
undoEnabled = true;
@@ -669,7 +670,14 @@ void QTextDocumentPrivate::remove(int pos, int length, QTextUndoCommand::Operati
{
if (length == 0)
return;
+ blockCursorAdjustment = true;
move(pos, -1, length, op);
+ blockCursorAdjustment = false;
+ foreach (QTextCursorPrivate *curs, cursors) {
+ if (curs->adjustPosition(pos, -length, op) == QTextCursorPrivate::CursorMoved) {
+ curs->changed = true;
+ }
+ }
}
void QTextDocumentPrivate::setCharFormat(int pos, int length, const QTextCharFormat &newFormat, FormatChangeMode mode)
@@ -1221,10 +1229,15 @@ void QTextDocumentPrivate::finishEdit()
}
}
- while (!changedCursors.isEmpty()) {
- QTextCursorPrivate *curs = changedCursors.takeFirst();
- emit q->cursorPositionChanged(QTextCursor(curs));
+ QList<QTextCursor> changedCursors;
+ foreach (QTextCursorPrivate *curs, cursors) {
+ if (curs->changed) {
+ curs->changed = false;
+ changedCursors.append(QTextCursor(curs));
+ }
}
+ foreach (const QTextCursor &cursor, changedCursors)
+ emit q->cursorPositionChanged(cursor);
contentsChanged();
@@ -1266,11 +1279,13 @@ void QTextDocumentPrivate::adjustDocumentChangesAndCursors(int from, int addedOr
if (!editBlock)
++revision;
- for (int i = 0; i < cursors.size(); ++i) {
- QTextCursorPrivate *curs = cursors.at(i);
- if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) {
- if (!changedCursors.contains(curs))
- changedCursors.append(curs);
+ if (blockCursorAdjustment) {
+ ; // postpone, will be called again from QTextDocumentPrivate::remove()
+ } else {
+ foreach (QTextCursorPrivate *curs, cursors) {
+ if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) {
+ curs->changed = true;
+ }
}
}
@@ -1693,8 +1708,8 @@ bool QTextDocumentPrivate::ensureMaximumBlockCount()
void QTextDocumentPrivate::aboutToRemoveCell(int from, int to)
{
Q_ASSERT(from <= to);
- for (int i = 0; i < cursors.size(); ++i)
- cursors.at(i)->aboutToRemoveCell(from, to);
+ foreach (QTextCursorPrivate *curs, cursors)
+ curs->aboutToRemoveCell(from, to);
}
QT_END_NAMESPACE