sw/qa/extras/uiwriter/data/tdf149498.docx         |binary
 sw/qa/extras/uiwriter/uiwriter5.cxx               |   18 ++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    5 +++--
 3 files changed, 21 insertions(+), 2 deletions(-)

New commits:
commit 3ec09683bcbf85e42940108fa2ec0c49ad7d3d8b
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Fri Jul 21 17:35:12 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Jul 24 12:01:38 2023 +0200

    tdf#149498 sw: fix Undo crash at bookmark over cells
    
    Importing DOCX files with bookmarks between w:p paragraph
    elements resulted bookmark ranges over cell boundaries
    within text tables, causing crash with Undo.
    
    Partial revert of commit 9e1e88ad5cf2dc0e9b188c60930445652a6c7519
    to avoid bookmark ranges over cell boundaries, creating
    only collapsed bookmarks here, as before.
    
    Regression from commit 9e1e88ad5cf2dc0e9b188c60930445652a6c7519
    "tdf#145720 DOCX export: fix loss of tracked moving".
    
    Note: to avoid of another assertion, skip testing with
    debug builds.
    
    Change-Id: I3ed6daa55323f20130fcee6cc24d00a480731d0c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154743
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit b081a818b1c3024d7ec5cc5b3a251109a1d9b08d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154708
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/uiwriter/data/tdf149498.docx 
b/sw/qa/extras/uiwriter/data/tdf149498.docx
new file mode 100644
index 000000000000..b310e88aa735
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf149498.docx differ
diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index 88868f8086c2..dfe0cc80f7ec 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -2589,6 +2589,24 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf155747)
     assertXPath(pXmlDoc, "//page[1]//body/tab/row/cell", 1);
 }
 
+#ifndef DBG_UTIL
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf149498)
+{
+    // load a table, and delete the first column with enabled change tracking:
+    // now the column is not deleted silently, but keeps the deleted cell 
content,
+    // and only accepting it will result the deletion of the table column.
+    createSwDoc("tdf149498.docx");
+
+    // select table, copy, paste and Undo
+    dispatchCommand(mxComponent, ".uno:SelectAll", {});
+    dispatchCommand(mxComponent, ".uno:Copy", {});
+    dispatchCommand(mxComponent, ".uno:Paste", {});
+
+    // this would crash due to bookmark over cell boundary
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+}
+#endif
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testTdf150673_RedlineTableColumnDeletionWithExport)
 {
     // load a table, and delete the first column with enabled change tracking:
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 4a32891f2503..77a68dd5a535 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -8420,10 +8420,11 @@ void DomainMapper_Impl::StartOrEndBookmark( const 
OUString& rId )
                 // then  move the bookmark-End to the earlier paragraph
                 if (IsOutsideAParagraph())
                 {
-                    // keep bookmark range
+                    // keep bookmark range, if it doesn't exceed cell boundary
                     uno::Reference< text::XTextRange > xStart = 
xCursor->getStart();
                     xCursor->goLeft( 1, false );
-                    xCursor->gotoRange(xStart, true );
+                    if (m_nTableDepth == 0 || !m_bFirstParagraphInCell)
+                        xCursor->gotoRange(xStart, true );
                 }
                 uno::Reference< container::XNamed > xBkmNamed( xBookmark, 
uno::UNO_QUERY_THROW );
                 SAL_WARN_IF(aBookmarkIter->second.m_sBookmarkName.isEmpty(), 
"writerfilter.dmapper", "anonymous bookmark");

Reply via email to