Commit bb018a76 authored by C. Boemann's avatar C. Boemann

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
parent af46a26f
...@@ -43,8 +43,8 @@ public: ...@@ -43,8 +43,8 @@ public:
QTextCursor cursor; QTextCursor cursor;
KoTextInlineRdf *rdf; //< A textrange might have RDF, we own it. KoTextInlineRdf *rdf; //< A textrange might have RDF, we own it.
bool positionOnlyMode; bool positionOnlyMode;
int snapStart; int snapAnchor;
int snapEnd; int snapPos;
}; };
KoTextRange::KoTextRange(const QTextCursor &cursor) KoTextRange::KoTextRange(const QTextCursor &cursor)
...@@ -159,13 +159,13 @@ KoTextInlineRdf* KoTextRange::inlineRdf() const ...@@ -159,13 +159,13 @@ KoTextInlineRdf* KoTextRange::inlineRdf() const
void KoTextRange::snapshot() void KoTextRange::snapshot()
{ {
Q_D(KoTextRange); Q_D(KoTextRange);
d->snapStart = d->cursor.selectionStart(); d->snapAnchor = d->cursor.anchor();
d->snapEnd = d->cursor.selectionEnd(); d->snapPos = d->cursor.position();
} }
void KoTextRange::restore() void KoTextRange::restore()
{ {
Q_D(KoTextRange); Q_D(KoTextRange);
d->cursor.setPosition(d->snapStart); d->cursor.setPosition(d->snapAnchor);
d->cursor.setPosition(d->snapEnd, QTextCursor::KeepAnchor); d->cursor.setPosition(d->snapPos, QTextCursor::KeepAnchor);
} }
...@@ -81,6 +81,7 @@ void DeleteAnchorsCommand::redo() ...@@ -81,6 +81,7 @@ void DeleteAnchorsCommand::redo()
if (rangeManager) { if (rangeManager) {
foreach (KoAnchorTextRange *anchorRange, m_anchorRanges) { foreach (KoAnchorTextRange *anchorRange, m_anchorRanges) {
rangeManager->remove(anchorRange); rangeManager->remove(anchorRange);
m_document->markContentsDirty(anchorRange->position(), 0);
} }
} }
} }
...@@ -99,6 +100,7 @@ void DeleteAnchorsCommand::undo() ...@@ -99,6 +100,7 @@ void DeleteAnchorsCommand::undo()
if (rangeManager) { if (rangeManager) {
foreach (KoAnchorTextRange *anchorRange, m_anchorRanges) { foreach (KoAnchorTextRange *anchorRange, m_anchorRanges) {
rangeManager->insert(anchorRange); rangeManager->insert(anchorRange);
m_document->markContentsDirty(anchorRange->position(), 0);
} }
} }
m_deleteAnchors = false; m_deleteAnchors = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment