diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2022-07-28 19:06:59 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-07-30 09:02:07 +0200 |
commit | 640a6488a32e8f682788feb6cab01acfffca7fa7 (patch) | |
tree | 05c3d735e99a9afe6f94ef7b260ff420456f8006 /sc/source/ui/undo | |
parent | be32cb92103326da2c744bc85d82b9c788f4e98b (diff) |
sc: allow undo of typing in 2 views independent from each other
This commit follows the same pattern as
commit c72e500ccaf0ce2261c5233b80fba9342778f810
sw: allow undo of typing in 2 views independent from each other
with some changes since calc and writer have different undo/redo
infrastructure on top of SfxUndoManager.
Change-Id: Ib6e7e21caccb94752c01c529b5013553dba8b4f9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137579
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source/ui/undo')
-rw-r--r-- | sc/source/ui/undo/undobase.cxx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/sc/source/ui/undo/undobase.cxx b/sc/source/ui/undo/undobase.cxx index 8ce8bc9e82f0..b591b38aabc7 100644 --- a/sc/source/ui/undo/undobase.cxx +++ b/sc/source/ui/undo/undobase.cxx @@ -21,6 +21,7 @@ #include <svx/svdundo.hxx> #include <undobase.hxx> +#include <undocell.hxx> #include <refundo.hxx> #include <docsh.hxx> #include <tabvwsh.hxx> @@ -34,6 +35,7 @@ #include <column.hxx> #include <sortparam.hxx> #include <columnspanset.hxx> +#include <undomanager.hxx> ScSimpleUndo::ScSimpleUndo( ScDocShell* pDocSh ) : @@ -613,4 +615,68 @@ bool ScUndoWrapper::CanRepeat(SfxRepeatTarget& rTarget) const return false; } +ScUndoManager::~ScUndoManager() {} + +/** + * Checks if the topmost undo action owned by pView is independent from the topmost action undo + * action. + */ +bool ScUndoManager::IsViewUndoActionIndependent(const SfxViewShell* pView) const +{ + if (GetUndoActionCount() <= 1 || SdrUndoManager::GetRedoActionCount() > 0) + { + // Single or less undo, owned by another view; or redo actions that might depend on the + // current undo order. + return false; + } + + if (!pView) + { + return false; + } + + // Last undo action that doesn't belong to the view. + const SfxUndoAction* pTopAction = GetUndoAction(); + + ViewShellId nViewId = pView->GetViewShellId(); + + // Earlier undo action that belongs to the view, but is not the top one. + const SfxUndoAction* pViewAction = nullptr; + const SfxUndoAction* pAction = GetUndoAction(1); + if (pAction->GetViewShellId() == nViewId) + { + pViewAction = pAction; + } + + if (!pViewAction) + { + // Found no earlier undo action that belongs to the view. + return false; + } + + std::optional<ScRange> topRange = getAffectedRangeFromUndo(pTopAction); + if (!topRange) + return false; + + std::optional<ScRange> viewRange = getAffectedRangeFromUndo(pViewAction); + if (!viewRange) + return false; + + return !topRange->Intersects(*viewRange); +} + +std::optional<ScRange> ScUndoManager::getAffectedRangeFromUndo(const SfxUndoAction* pAction) +{ + auto pListAction = dynamic_cast<const SfxListUndoAction*>(pAction); + if (!pListAction) + return std::nullopt; + if (pListAction->maUndoActions.size() > 1) + return std::nullopt; + auto pTopScUndoEnterData = dynamic_cast<ScUndoEnterData*>(pListAction->maUndoActions[0].pAction.get()); + if (!pTopScUndoEnterData) + return std::nullopt; + return pTopScUndoEnterData->GetPositionAddress(); +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |