desktop/qa/desktop_lib/test_desktop_lib.cxx | 11 ++++++++++- editeng/source/editeng/editobj.cxx | 21 +++++++++++++++++++++ editeng/source/editeng/editobj2.hxx | 1 + include/editeng/editobj.hxx | 3 +++ sw/source/uibase/wrtsh/wrtsh1.cxx | 5 +++++ 5 files changed, 40 insertions(+), 1 deletion(-)
New commits: commit c73958bf812d4c1f0b08354bcd86cec5802c6d4e Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Wed Jan 1 21:55:00 2025 +0000 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Fri Jan 17 11:38:05 2025 +0100 undo/redo of comment insertion assumes Par2 content matches TextObject contents (as much as conversion to plain text makes possible) To make things easier, add an EditTextObject::GetText() like EditEngine::GetText() that serializes multiple paragraphs in an equivalent way so there isn't a need to create an editengine just to do this conversion. Modify and extend DesktopLOKTest::testCommentsCallbacksWriter to use a html payload and add a undo/redo to it. Change-Id: I4d895138e919bab54ebbbcb966f9b9faef574086 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179594 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180377 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 66b29c4cd1aa..a91270f94bad 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -2595,7 +2595,7 @@ void DesktopLOKTest::testCommentsCallbacksWriter() CPPUNIT_ASSERT_EQUAL(nCommentId2, aView2.m_aCommentCallbackResult.get<int>("id")); // Reply to nCommentId1 again - aCommandArgs = "{ \"Id\": { \"type\": \"string\", \"value\": \"" + OString::number(nCommentId1) + "\" }, \"Text\": { \"type\": \"string\", \"value\": \"Reply comment again\" } }"; + aCommandArgs = "{ \"Id\": { \"type\": \"string\", \"value\": \"" + OString::number(nCommentId1) + "\" }, \"Html\": { \"type\": \"string\", \"value\": \"Reply comment again\" } }"; pDocument->pClass->postUnoCommand(pDocument, ".uno:ReplyComment", aCommandArgs.getStr(), false); Scheduler::ProcessEventsToIdle(); @@ -2607,6 +2607,15 @@ void DesktopLOKTest::testCommentsCallbacksWriter() CPPUNIT_ASSERT_EQUAL(std::string("<div>Reply comment again</div>"), aView1.m_aCommentCallbackResult.get<std::string>("html")); CPPUNIT_ASSERT_EQUAL(std::string("<div>Reply comment again</div>"), aView2.m_aCommentCallbackResult.get<std::string>("html")); + // Ensure that an undo and redo restores the html contents + aView1.m_aCommentCallbackResult.clear(); + aView2.m_aCommentCallbackResult.clear(); + pDocument->pClass->postUnoCommand(pDocument, ".uno:Undo", "", false); + pDocument->pClass->postUnoCommand(pDocument, ".uno:Redo", "", false); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(std::string("<div>Reply comment again</div>"), aView1.m_aCommentCallbackResult.get<std::string>("html")); + CPPUNIT_ASSERT_EQUAL(std::string("<div>Reply comment again</div>"), aView2.m_aCommentCallbackResult.get<std::string>("html")); + // .uno:ViewAnnotations returns total of 5 comments boost::property_tree::ptree aTree; char* pJSON = pDocument->m_pDocumentClass->getCommandValues(pDocument, ".uno:ViewAnnotations"); diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index 6f7182f383af..536d7c2c6acb 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -30,6 +30,7 @@ #include <editeng/flditem.hxx> #include <svl/sharedstringpool.hxx> +#include <rtl/ustrbuf.hxx> #include <libxml/xmlwriter.h> #include <algorithm> @@ -398,6 +399,26 @@ OUString EditTextObjectImpl::GetText(sal_Int32 nPara) const return maContents[nPara]->GetText(); } +OUString EditTextObjectImpl::GetText(LineEnd eEnd) const +{ + const size_t nParas = maContents.size(); + if (nParas == 0) + return OUString(); + + const OUString aSep = EditDoc::GetSepStr(eEnd); + + OUStringBuffer aBuffer; + + for (size_t nPara = 0; nPara < nParas; ++nPara) + { + if (!aSep.isEmpty() && nPara > 0) + aBuffer.append(aSep); + aBuffer.append(maContents[nPara]->GetText()); + } + + return aBuffer.makeStringAndClear(); +} + sal_Int32 EditTextObjectImpl::GetTextLen(sal_Int32 nPara ) const { if (nPara < 0 || o3tl::make_unsigned(nPara) >= maContents.size()) diff --git a/editeng/source/editeng/editobj2.hxx b/editeng/source/editeng/editobj2.hxx index f1bfa4e773ac..9cfe1c09f5e5 100644 --- a/editeng/source/editeng/editobj2.hxx +++ b/editeng/source/editeng/editobj2.hxx @@ -227,6 +227,7 @@ public: virtual sal_Int32 GetParagraphCount() const override; virtual OUString GetText(sal_Int32 nParagraph) const override; + virtual OUString GetText(LineEnd eEnd = LINEEND_LF) const override; virtual sal_Int32 GetTextLen(sal_Int32 nParagraph) const override; virtual void ClearPortionInfo() override; diff --git a/include/editeng/editobj.hxx b/include/editeng/editobj.hxx index b78b1a918b27..840f2e291da7 100644 --- a/include/editeng/editobj.hxx +++ b/include/editeng/editobj.hxx @@ -24,6 +24,7 @@ #include <editeng/editengdllapi.h> #include <editeng/macros.hxx> #include <svl/languageoptions.hxx> +#include <tools/lineend.hxx> #include <com/sun/star/text/textfield/Type.hpp> @@ -87,6 +88,8 @@ public: virtual OUString GetText(sal_Int32 nPara) const = 0; + virtual OUString GetText(LineEnd eEnd = LINEEND_LF) const = 0; + virtual sal_Int32 GetTextLen(sal_Int32 nPara) const = 0; bool HasText(sal_Int32 nPara) const { return GetTextLen(nPara) > 0; } diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index dcbeefc2a14b..cd5572e44d6a 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -36,6 +36,7 @@ #include <tools/bigint.hxx> #include <svtools/insdlg.hxx> #include <sfx2/ipclient.hxx> +#include <editeng/editeng.hxx> #include <editeng/editobj.hxx> #include <editeng/formatbreakitem.hxx> #include <editeng/svxacorr.hxx> @@ -2278,6 +2279,7 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq) Outliner aOutliner(&pDocSh->GetPool(), OutlinerMode::TextObject); SwPostItHelper::ImportHTML(aOutliner, pHtmlItem->GetValue()); oTextPara = aOutliner.CreateParaObject(); + sText = aOutliner.GetEditEngine().GetText(); } // If we have a text already registered for answer, use that @@ -2291,7 +2293,10 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq) } const EditTextObject& rTextObject = pAnswer->GetTextObject(); if (rTextObject.GetParagraphCount() != 1 || !rTextObject.GetText(0).isEmpty()) + { oTextPara = *pAnswer; + sText = rTextObject.GetText(); + } } if ( HasSelection() && !IsTableMode() )