sw/inc/editsh.hxx | 1 + sw/inc/strings.hrc | 1 + sw/inc/swundo.hxx | 1 + sw/qa/core/edit/edit.cxx | 12 ++++++++++++ sw/source/core/edit/edredln.cxx | 21 ++++++++++++++++++++- sw/source/core/undo/undobj.cxx | 3 +++ 6 files changed, 38 insertions(+), 1 deletion(-)
New commits: commit 86df6046e389af4cd0c984650d3236cd17448ab3 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Apr 1 09:13:26 2025 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue Apr 1 11:34:02 2025 +0200 cool#11357 sw redline reinstate: fix undo string for a single redline Open a document with an insert redline, reinstate, check the undo stack, it says we have a "delete" on it. This is technically true, but the user did a reinstate, which happens to be implemented as a delete for inserts. Fix the problem by adding a dedicated SwUndoId::REINSTATE_REDLINE and use that when reinstating a single redline. The "reinstate multiple redlines at once" case still needs fixing. Change-Id: Ib2c58ac41fcb86b2f947b041ada318ea2a361e8b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183573 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index f35142c7b277..03ed601a1d8e 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -960,6 +960,7 @@ public: bool IsRedlineOn() const; SW_DLLPUBLIC SwRedlineTable::size_type GetRedlineCount() const; const SwRangeRedline& GetRedline( SwRedlineTable::size_type nPos ) const; + SwRangeRedline& GetRedline( SwRedlineTable::size_type nPos ); SW_DLLPUBLIC bool AcceptRedline( SwRedlineTable::size_type nPos ); SW_DLLPUBLIC bool RejectRedline( SwRedlineTable::size_type nPos ); bool AcceptRedlinesInSelection(); diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index aef6984053e8..950b67c3bd01 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -495,6 +495,7 @@ #define STR_CHANGEFTN NC_("STR_CHANGEFTN", "Modify footnote") #define STR_ACCEPT_REDLINE NC_("STR_ACCEPT_REDLINE", "Accept change: $1") #define STR_REJECT_REDLINE NC_("STR_REJECT_REDLINE", "Reject change: $1") +#define STR_REINSTATE_REDLINE NC_("STR_REINSTATE_REDLINE", "Reinstate change: $1") #define STR_SPLIT_TABLE NC_("STR_SPLIT_TABLE", "Split Table") #define STR_DONTEXPAND NC_("STR_DONTEXPAND", "Stop attribute") #define STR_AUTOCORRECT NC_("STR_AUTOCORRECT", "AutoCorrect") diff --git a/sw/inc/swundo.hxx b/sw/inc/swundo.hxx index 4641f0e9e9af..29e66c2c5349 100644 --- a/sw/inc/swundo.hxx +++ b/sw/inc/swundo.hxx @@ -182,6 +182,7 @@ enum class SwUndoId FLYFRMFMT_DECORATIVE = 150, MAKE_FOOTNOTES_ENDNOTES = 151, MAKE_ENDNOTES_FOOTNOTES = 152, + REINSTATE_REDLINE = 153, }; OUString GetUndoComment(SwUndoId eId); diff --git a/sw/qa/core/edit/edit.cxx b/sw/qa/core/edit/edit.cxx index ce12c6ac3a72..9c33f3e0bcf1 100644 --- a/sw/qa/core/edit/edit.cxx +++ b/sw/qa/core/edit/edit.cxx @@ -16,6 +16,7 @@ #include <wrtsh.hxx> #include <unotxdoc.hxx> #include <IDocumentRedlineAccess.hxx> +#include <IDocumentUndoRedo.hxx> #include <swmodule.hxx> #include <redline.hxx> #include <ndtxt.hxx> @@ -118,6 +119,17 @@ CPPUNIT_TEST_FIXTURE(Test, testRedlineReinstateSingleInsert) CPPUNIT_ASSERT(rRedlineData.Next()); const SwRedlineData& rInnerRedlineData = *rRedlineData.Next(); CPPUNIT_ASSERT_EQUAL(RedlineType::Insert, rInnerRedlineData.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, testRedlineReinstateInsertsInSelection) diff --git a/sw/source/core/edit/edredln.cxx b/sw/source/core/edit/edredln.cxx index 39f5049b5fd4..cd75f5cb39e9 100644 --- a/sw/source/core/edit/edredln.cxx +++ b/sw/source/core/edit/edredln.cxx @@ -18,6 +18,8 @@ */ #include <IDocumentRedlineAccess.hxx> +#include <IDocumentUndoRedo.hxx> +#include <SwRewriter.hxx> #include <docary.hxx> #include <redline.hxx> #include <doc.hxx> @@ -59,6 +61,11 @@ const SwRangeRedline& SwEditShell::GetRedline( SwRedlineTable::size_type nPos ) return *GetDoc()->getIDocumentRedlineAccess().GetRedlineTable()[ nPos ]; } +SwRangeRedline& SwEditShell::GetRedline(SwRedlineTable::size_type nPos) +{ + return const_cast<SwRangeRedline&>(const_cast<const SwEditShell*>(this)->GetRedline(nPos)); +} + static void lcl_InvalidateAll( SwViewShell* pSh ) { for(SwViewShell& rCurrentShell : pSh->GetRingContainer()) @@ -128,11 +135,23 @@ void SwEditShell::ReinstateRedline(SwRedlineTable::size_type nPos) SetRedlineFlags(nMode | RedlineFlags::On, /*bRecordAllViews=*/false); } - const SwRangeRedline& rRedline = GetRedline(nPos); + SwRangeRedline& rRedline = GetRedline(nPos); SwPaM aPaM(*rRedline.GetPoint()); aPaM.SetMark(); *aPaM.GetMark() = *rRedline.GetMark(); + + IDocumentUndoRedo& rIDUR = GetDoc()->GetIDocumentUndoRedo(); + if (rIDUR.DoesUndo()) + { + SwRewriter aRewriter; + aRewriter.AddRule(UndoArg1, rRedline.GetDescr()); + rIDUR.StartUndo(SwUndoId::REINSTATE_REDLINE, &aRewriter); + } ReinstatePaM(rRedline, aPaM); + if (rIDUR.DoesUndo()) + { + rIDUR.EndUndo(SwUndoId::END, nullptr); + } EndAllAction(); } diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx index 93aad1069a57..c4271727ebc2 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -691,6 +691,9 @@ OUString GetUndoComment(SwUndoId eId) case SwUndoId::MAKE_ENDNOTES_FOOTNOTES: pId = STR_UNDO_MAKE_ENDNOTES_FOOTNOTES; break; + case SwUndoId::REINSTATE_REDLINE: + pId = STR_REINSTATE_REDLINE; + break; } assert(pId);