summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-11-12 08:39:35 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-11-12 12:46:22 +0100
commit39f231360013e944a8713248359662b9f282d902 (patch)
treec3be11063a963835c61954f96da6026f0626ed28 /svl
parente1a9d507d92cc793f7f10f87cdd7a5534faa5759 (diff)
sw, out of order undo: allow multiple actions from other views
Previously we assumed that the action to be executed is always exactly the top of the undo stack minus 1 element. Extend this, so that in case an other view appends two or more elements to the undo stack, we still find our undo action. Obviously only do this if all those undo actions are independent from us. This requires replacing the swap in svl/ with a move-out + move a range down + move in construct. Change-Id: Ic12d32d6eb5e77618d99eddb4fa096802f32d655 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125076 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'svl')
-rw-r--r--svl/source/undo/undo.cxx18
1 files changed, 13 insertions, 5 deletions
diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx
index f84d2cda185a..e820a3cbb9d1 100644
--- a/svl/source/undo/undo.cxx
+++ b/svl/source/undo/undo.cxx
@@ -683,13 +683,21 @@ bool SfxUndoManager::ImplUndo( SfxUndoContext* i_contextOrNull )
return false;
}
- if (i_contextOrNull && i_contextOrNull->GetUndoOffset() == 1)
+ if (i_contextOrNull && i_contextOrNull->GetUndoOffset() > 0)
{
- if (m_xData->pActUndoArray->nCurUndoAction >= 2)
+ size_t nCurrent = m_xData->pActUndoArray->nCurUndoAction;
+ size_t nOffset = i_contextOrNull->GetUndoOffset();
+ if (nCurrent >= nOffset + 1)
{
- std::swap(
- m_xData->pActUndoArray->maUndoActions[m_xData->pActUndoArray->nCurUndoAction - 1],
- m_xData->pActUndoArray->maUndoActions[m_xData->pActUndoArray->nCurUndoAction - 2]);
+ // Move out the action we want to execute.
+ MarkedUndoAction aAction
+ = std::move(m_xData->pActUndoArray->maUndoActions[nCurrent - 1 - nOffset]);
+ // Move the actions after aAction down by one.
+ std::move(m_xData->pActUndoArray->maUndoActions.data() + nCurrent - nOffset,
+ m_xData->pActUndoArray->maUndoActions.data() + nCurrent,
+ m_xData->pActUndoArray->maUndoActions.data() + nCurrent - nOffset - 1);
+ // Move aAction to the top.
+ m_xData->pActUndoArray->maUndoActions[nCurrent - 1] = std::move(aAction);
}
}