sw/inc/undobj.hxx | 2 - sw/qa/core/doc/doc.cxx | 30 ++++++++++++++++++++++++++ sw/source/core/doc/DocumentRedlineManager.cxx | 4 +-- sw/source/core/inc/UndoRedline.hxx | 3 +- 4 files changed, 35 insertions(+), 4 deletions(-)
New commits: commit 76c2168a276f0996deeac08ce176525821fb056e Author: Miklos Vajna <[email protected]> AuthorDate: Mon Jun 23 11:47:49 2025 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Mon Jun 23 18:14:25 2025 +0200 tdf#166319 sw interdependent redlines: fix bad accept undo action for reject See <https://gerrit.libreoffice.org/c/core/+/186646/2#message-86a47ee78fb9a0c6d4a8e355a06c5c6931d66f6b>, a reject UI action resulted in an accept undo action, which was inconsistent. I added this in commit 8b5435d6e49c3d0237bc4a13ff5253dcb1c915f7 (tdf#166319 sw interdependent redlines: fix undo of del on top of ins, 2025-04-25), at that time SwUndoRejectRedline had no way to store hierarchical redlines. Fix the problem by asking for a hierarhical copy using the API added in commit 5f4ed6e34d71b578f5facef04d3a0ae2df81531b (tdf#166319 sw interdependent redlines: fix undo of reject of ins-then-del's del, 2025-06-11): this way we don't need to create a fake accept undo action & the "underlying" redline data won't be lost, either. Change-Id: I92201881fb67e3eca95a805b6a0da3a166a863fe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186840 Tested-by: Jenkins Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sw/inc/undobj.hxx b/sw/inc/undobj.hxx index e73bc5b5b5c1..885db7221593 100644 --- a/sw/inc/undobj.hxx +++ b/sw/inc/undobj.hxx @@ -49,7 +49,7 @@ namespace sw { class RepeatContext; } -class SwUndo +class SW_DLLPUBLIC SwUndo : public SfxUndoAction { SwUndoId const m_nId; diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx index 2ad808f958c5..56b4fb0fd44b 100644 --- a/sw/qa/core/doc/doc.cxx +++ b/sw/qa/core/doc/doc.cxx @@ -43,6 +43,7 @@ #include <sortedobjs.hxx> #include <itabenum.hxx> #include <redline.hxx> +#include <UndoRedline.hxx> /// Covers sw/source/core/doc/ fixes. class SwCoreDocTest : public SwModelTestBase @@ -774,6 +775,35 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testInsThenDelRejectUndo) const SwRedlineData& rInnerRedlineData = *rRedlineData1.Next(); CPPUNIT_ASSERT_EQUAL(RedlineType::Insert, rInnerRedlineData.GetType()); CPPUNIT_ASSERT_EQUAL(RedlineType::Insert, rRedlines[2]->GetType()); + + // And when rejecting the "ins" part of ins-then-del: + pWrtShell->RejectRedline(0); + + // Then make sure "reject" (and no accept) was created on the undo stack: + sw::UndoManager& rUndoManager = pDoc->GetUndoManager(); + int nAccepts = 0; + auto pListUndoAction = dynamic_cast<SfxListUndoAction*>(rUndoManager.GetUndoAction()); + if (pListUndoAction) + { + for (const auto& rMarkedAction : pListUndoAction->maUndoActions) + { + auto pUndo = dynamic_cast<SwUndoRedline*>(rMarkedAction.pAction.get()); + if (!pUndo) + { + continue; + } + + if (pUndo->GetUserId() == SwUndoId::ACCEPT_REDLINE) + { + ++nAccepts; + } + } + } + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 1 + // i.e. an "accept" undo action was created by RejectRedline(). + CPPUNIT_ASSERT_EQUAL(0, nAccepts); } CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testInsThenFormat) diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx b/sw/source/core/doc/DocumentRedlineManager.cxx index 69e67a24a126..bbd3fd531e0a 100644 --- a/sw/source/core/doc/DocumentRedlineManager.cxx +++ b/sw/source/core/doc/DocumentRedlineManager.cxx @@ -3712,13 +3712,13 @@ bool DocumentRedlineManager::RejectRedlineRange(SwRedlineTable::size_type nPosOr std::unique_ptr<SwUndoRedline> pUndoRdl; if (eInnerType == RedlineType::Delete && eOuterType == RedlineType::Format) { - // Format on insert: record rejection of the underlying insert. + // Format on delete: record rejection of the underlying delete. pUndoRdl = std::make_unique<SwUndoRejectRedline>(*pTmp, /*nDepth=*/1, /*bHierarchical=*/true); } else { // The Insert/Delete redline we want to reject has another type of redline too - pUndoRdl = std::make_unique<SwUndoAcceptRedline>(*pTmp); + pUndoRdl = std::make_unique<SwUndoRejectRedline>(*pTmp, /*nDepth=*/0, /*bHierarchical=*/true); } #if OSL_DEBUG_LEVEL > 0 pUndoRdl->SetRedlineCountDontCheck(true); diff --git a/sw/source/core/inc/UndoRedline.hxx b/sw/source/core/inc/UndoRedline.hxx index 1e1033d319d5..4a7a707c8516 100644 --- a/sw/source/core/inc/UndoRedline.hxx +++ b/sw/source/core/inc/UndoRedline.hxx @@ -29,7 +29,7 @@ class SwRangeRedline; class SwRedlineSaveDatas; class SwUndoDelete; -class SwUndoRedline : public SwUndo, public SwUndRng +class SW_DLLPUBLIC SwUndoRedline : public SwUndo, public SwUndRng { protected: std::unique_ptr<SwRedlineData> mpRedlData; @@ -55,6 +55,7 @@ public: #if OSL_DEBUG_LEVEL > 0 void SetRedlineCountDontCheck(bool bCheck); #endif + SwUndoId GetUserId() const { return mnUserId; } void dumpAsXml(xmlTextWriterPtr pWriter) const override; };
