From 8e8e72f08b01a284cf1a90b888d48acfb6a33d2e Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 10 Nov 2021 08:50:08 +0100 Subject: sw: allow undo of typing in 2 views independent from each other Undoing out of order is dangerous by default, so limit this to a very specific case as a start, that allows growing in follow-up commits. For now, allow out of order undo if: 1) redo stack is empty 2) we're in LOK mode (different views represent different users) 3) we undo a single action (count is 1) 4) the top undo action doesn't belong to the current view 5) the top and the previous undo actions are independent Which only requires that SwUndoInsert::UndoImpl() is independent for two different paragraphs, which seems to be the case. Independent undo actions opt in for this, currently the only such allowed undo action is SwUndoInsert ("typing"), which adds characters to a single text node. Even those are only considered independent if they operate on different text nodes. On the positive side, this allows out of order undo in the frequent case where two users collaborate on a long document and they just type some new content into the document at different paragraphs. Change-Id: Ibb4551e8f7046b4947491b8bf751eaa0cbb2d060 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124949 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- svl/source/undo/undo.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'svl') diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx index 630bb9deea5b..0c081b152c3a 100644 --- a/svl/source/undo/undo.cxx +++ b/svl/source/undo/undo.cxx @@ -683,6 +683,16 @@ bool SfxUndoManager::ImplUndo( SfxUndoContext* i_contextOrNull ) return false; } + if (i_contextOrNull && i_contextOrNull->GetUndoOffset() == 1) + { + if (m_xData->pActUndoArray->nCurUndoAction >= 2) + { + std::swap( + m_xData->pActUndoArray->maUndoActions[m_xData->pActUndoArray->nCurUndoAction - 1], + m_xData->pActUndoArray->maUndoActions[m_xData->pActUndoArray->nCurUndoAction - 2]); + } + } + SfxUndoAction* pAction = m_xData->pActUndoArray->maUndoActions[ --m_xData->pActUndoArray->nCurUndoAction ].pAction.get(); const OUString sActionComment = pAction->GetComment(); try -- cgit