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 ee1b0982834976638697e47a35b4999e6df9a028
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Jan 1 21:55:00 2025 +0000
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Jan 3 08:22:32 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>

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx 
b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index f6429bc7f4d9..f16073deb9de 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2597,7 +2597,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();
 
@@ -2609,6 +2609,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 762cac112ddb..fd5ac4b7fc76 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>
@@ -392,6 +393,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();
+}
+
 void EditTextObjectImpl::ClearPortionInfo()
 {
     mpPortionInfo.reset();
diff --git a/editeng/source/editeng/editobj2.hxx 
b/editeng/source/editeng/editobj2.hxx
index fd1f1437e910..322057c89fa1 100644
--- a/editeng/source/editeng/editobj2.hxx
+++ b/editeng/source/editeng/editobj2.hxx
@@ -225,6 +225,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 void ClearPortionInfo() override;
 
diff --git a/include/editeng/editobj.hxx b/include/editeng/editobj.hxx
index 5badaf8e8a2a..f73bb4d3274b 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 void ClearPortionInfo() = 0;
 
     virtual bool HasOnlineSpellErrors() const = 0;
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx 
b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 7b1d9236c099..4e3dd61bbd5b 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>
@@ -2267,6 +2268,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
@@ -2280,7 +2282,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() )

Reply via email to