From bb018a76bc09fe680ab0c4406dbbc525f5708b99 Mon Sep 17 00:00:00 2001 From: "C. Boemann" Date: Thu, 15 Jan 2015 15:05:46 +0100 Subject: [PATCH] Fix undo redo of textranges - we might have swapped anchor and pos in general that would not be that big a deal if not for a qt bug which makes the anchor travel even if the qtextcursor has keepPositionOnInsert() == true There was another part to this bug - we didn't make sure the text was relayouted so in short: the anchor was lost (misplaced) and the relayout was never initiated BUG: 342869 --- libs/kotext/KoTextRange.cpp | 12 ++++++------ libs/kotext/commands/DeleteAnchorsCommand.cpp | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/kotext/KoTextRange.cpp b/libs/kotext/KoTextRange.cpp index ac33906a69..40cb737531 100644 --- a/libs/kotext/KoTextRange.cpp +++ b/libs/kotext/KoTextRange.cpp @@ -43,8 +43,8 @@ public: QTextCursor cursor; KoTextInlineRdf *rdf; //< A textrange might have RDF, we own it. bool positionOnlyMode; - int snapStart; - int snapEnd; + int snapAnchor; + int snapPos; }; KoTextRange::KoTextRange(const QTextCursor &cursor) @@ -159,13 +159,13 @@ KoTextInlineRdf* KoTextRange::inlineRdf() const void KoTextRange::snapshot() { Q_D(KoTextRange); - d->snapStart = d->cursor.selectionStart(); - d->snapEnd = d->cursor.selectionEnd(); + d->snapAnchor = d->cursor.anchor(); + d->snapPos = d->cursor.position(); } void KoTextRange::restore() { Q_D(KoTextRange); - d->cursor.setPosition(d->snapStart); - d->cursor.setPosition(d->snapEnd, QTextCursor::KeepAnchor); + d->cursor.setPosition(d->snapAnchor); + d->cursor.setPosition(d->snapPos, QTextCursor::KeepAnchor); } diff --git a/libs/kotext/commands/DeleteAnchorsCommand.cpp b/libs/kotext/commands/DeleteAnchorsCommand.cpp index 02033b08f8..123c2a62c6 100644 --- a/libs/kotext/commands/DeleteAnchorsCommand.cpp +++ b/libs/kotext/commands/DeleteAnchorsCommand.cpp @@ -81,6 +81,7 @@ void DeleteAnchorsCommand::redo() if (rangeManager) { foreach (KoAnchorTextRange *anchorRange, m_anchorRanges) { rangeManager->remove(anchorRange); + m_document->markContentsDirty(anchorRange->position(), 0); } } } @@ -99,6 +100,7 @@ void DeleteAnchorsCommand::undo() if (rangeManager) { foreach (KoAnchorTextRange *anchorRange, m_anchorRanges) { rangeManager->insert(anchorRange); + m_document->markContentsDirty(anchorRange->position(), 0); } } m_deleteAnchors = false; -- GitLab