sw/qa/core/edit/edit.cxx | 11 +++++++++++ sw/source/core/edit/edredln.cxx | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+)
New commits: commit 7d702ebbfcda41ce2972e30b2a1e493c320df67c Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Apr 2 09:10:39 2025 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Apr 2 16:19:40 2025 +0200 cool#11357 sw redline reinstate: fix undo count & string for multiple redlines Open a document with insert redlines, reinstate, check the undo stack, it says it has multiple undo actions. This is technically true, but the user did a reinstate, which happens to be implemented as deletions. Fix the problem by using SwUndoId::REINSTATE_REDLINE in SwEditShell::ReinstateRedlinesInSelection(), too. This fixes both the undo count (now one reinstate results in one user-visible action) & the string to say reinstate. Change-Id: I8f59fa6334876ef1bd860b7aa41c0ed7d35cbf31 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183623 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/core/edit/edit.cxx b/sw/qa/core/edit/edit.cxx index 9c33f3e0bcf1..35a278b37ec2 100644 --- a/sw/qa/core/edit/edit.cxx +++ b/sw/qa/core/edit/edit.cxx @@ -180,6 +180,17 @@ CPPUNIT_TEST_FIXTURE(Test, testRedlineReinstateInsertsInSelection) CPPUNIT_ASSERT(rRedlineData2.Next()); const SwRedlineData& rInnerRedlineData2 = *rRedlineData2.Next(); CPPUNIT_ASSERT_EQUAL(RedlineType::Insert, rInnerRedlineData2.GetType()); + + // And when checking the undo stack: + SwUndoId nUndoId = SwUndoId::EMPTY; + pDoc->GetIDocumentUndoRedo().GetLastUndoInfo(nullptr, &nUndoId); + + // Then make sure we get the relevant undo ID: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 153 (REINSTATE_REDLINE) + // - Actual : 1 (DELETE) + // i.e. the undo ID was wrong. + CPPUNIT_ASSERT_EQUAL(SwUndoId::REINSTATE_REDLINE, nUndoId); } CPPUNIT_TEST_FIXTURE(Test, testRedlineReinstateSinglePlainDelete) diff --git a/sw/source/core/edit/edredln.cxx b/sw/source/core/edit/edredln.cxx index 8c6ac1ec20f6..8c1955cad571 100644 --- a/sw/source/core/edit/edredln.cxx +++ b/sw/source/core/edit/edredln.cxx @@ -27,6 +27,7 @@ #include <frmtool.hxx> #include <docsh.hxx> #include <swdtflvr.hxx> +#include <strings.hrc> RedlineFlags SwEditShell::GetRedlineFlags() const { @@ -247,6 +248,12 @@ void SwEditShell::ReinstateRedlinesInSelection() // redlines is not wanted. std::vector<SwRangeRedline*> aRedlines(rTable.begin(), rTable.end()); + IDocumentUndoRedo& rIDUR = GetDoc()->GetIDocumentUndoRedo(); + if (rIDUR.DoesUndo()) + { + rIDUR.StartUndo(SwUndoId::REINSTATE_REDLINE, nullptr); + } + int nRedlines = 0; for (size_t nIndex = 0; nIndex < aRedlines.size(); ++nIndex) { const SwRangeRedline& rRedline = *aRedlines[nIndex]; @@ -284,6 +291,19 @@ void SwEditShell::ReinstateRedlinesInSelection() aPaM.SetMark(); *aPaM.GetMark() = *pStart; ReinstatePaM(rRedline, aPaM); + ++nRedlines; + } + if (rIDUR.DoesUndo()) + { + OUString aWith; + { + SwRewriter aRewriter; + aRewriter.AddRule(UndoArg1, OUString::number(nRedlines)); + aWith = aRewriter.Apply(SwResId(STR_N_REDLINES)); + } + SwRewriter aRewriter; + aRewriter.AddRule(UndoArg1, aWith); + rIDUR.EndUndo(SwUndoId::REINSTATE_REDLINE, &aRewriter); } EndAllAction();