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 fbf9465e2bc9f878723674d1eff13e0c69656057 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Apr 1 09:13:26 2025 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Apr 1 16:07:27 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/+/183589 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index fd768d85e078..00ed2ad9dacf 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -957,6 +957,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 22187814eeee..9c6b5b9d4d3e 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 294578c16061..11255e7966cd 100644 --- a/sw/inc/swundo.hxx +++ b/sw/inc/swundo.hxx @@ -183,6 +183,7 @@ enum class SwUndoId MAKE_FOOTNOTES_ENDNOTES = 151, MAKE_ENDNOTES_FOOTNOTES = 152, CONVERT_FIELD_TO_TEXT = 153, + REINSTATE_REDLINE = 154, }; 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 e778a33b3e82..8c6ac1ec20f6 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> @@ -61,6 +63,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()) @@ -130,11 +137,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 e69bebbd8666..6447a280b45b 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -694,6 +694,9 @@ OUString GetUndoComment(SwUndoId eId) case SwUndoId::CONVERT_FIELD_TO_TEXT: pId = STR_UNDO_CONVERT_FIELD_TO_TEXT; break; + case SwUndoId::REINSTATE_REDLINE: + pId = STR_REINSTATE_REDLINE; + break; } assert(pId);