sw/qa/extras/uiwriter/data/tdf147180.fodt |   48 ++++++++++++++++++++++++++++++
 sw/qa/extras/uiwriter/uiwriter5.cxx       |   36 ++++++++++++++++++++++
 sw/source/core/doc/docredln.cxx           |   14 ++++++++
 3 files changed, 98 insertions(+)

New commits:
commit a9cf949efcfdb9eb459cabe1b9e15f993e789c73
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Fri Apr 28 13:59:01 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue May 2 17:05:56 2023 +0200

    tdf#147180 sw: fix lost change tracking of modified tables
    
    Tracked text insertion can contain tables in a single
    redline (i.e. change), e.g. in case of newly inserted
    or deleted tables. Editing this tracked table, e.g.
    typing new text in a cell, deleting rows or columns
    resulted loss of the change tracking of the table by
    replacing the single redline over the table with
    redlines within the cells. Now add tracked row changes
    to the (not empty) table rows to keep change tracking
    of the table.
    
    Follow-up to commit 1555ba4dd9e90f0dfd39df952c3d2fd5e755e2f5
    "tdf#150824 sw DOCX: fix export of new tracked tables" and
    commit 05366b8e6683363688de8708a3d88cf144c7a2bf
    "tdf#60382 sw offapi: add change tracking of table/row deletion".
    
    Change-Id: I8eb46b240c3f5036b5b0966e2a523e369cb02e41
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151169
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/uiwriter/data/tdf147180.fodt 
b/sw/qa/extras/uiwriter/data/tdf147180.fodt
new file mode 100644
index 000000000000..cc13e543f5f3
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf147180.fodt
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; xmlns:c
 alcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:
 meta:1.0" 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+  <office:text>
+   <text:tracked-changes text:track-changes="false">
+    <text:changed-region xml:id="ct94228217946240" text:id="ct94228217946240">
+     <text:insertion>
+      <office:change-info>
+       <dc:creator>Unknown Author</dc:creator>
+       <dc:date>2022-09-06T14:47:25</dc:date>
+      </office:change-info>
+     </text:insertion>
+    </text:changed-region>
+   </text:tracked-changes>
+   <text:change-start text:change-id="ct94228217946240"/>
+   <table:table table:name="Table1" table:style-name="Table1">
+    <table:table-column table:style-name="Table1.A"/>
+    <table:table-column table:style-name="Table1.B"/>
+    <table:table-row>
+     <table:table-cell table:style-name="Table1.A1" office:value-type="string">
+      <text:p text:style-name="Table_20_Contents">A1</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="Table1.B1" office:value-type="string">
+      <text:p text:style-name="Table_20_Contents">B1</text:p>
+     </table:table-cell>
+    </table:table-row>
+    <table:table-row>
+     <table:table-cell table:style-name="Table1.A2" office:value-type="string">
+      <text:p text:style-name="Table_20_Contents">A2</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="Table1.B2" office:value-type="string">
+      <text:p text:style-name="Table_20_Contents">B2</text:p>
+     </table:table-cell>
+    </table:table-row>
+    <table:table-row>
+     <table:table-cell table:style-name="Table1.A2" office:value-type="string">
+      <text:p text:style-name="Table_20_Contents">A3</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="Table1.B2" office:value-type="string">
+      <text:p text:style-name="Table_20_Contents">B3</text:p>
+     </table:table-cell>
+    </table:table-row>
+   </table:table>
+   <text:p text:style-name="Standard"><text:change-end 
text:change-id="ct94228217946240"/></text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index b7a9a08d4316..ec2d8386d711 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -2381,6 +2381,42 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf144748)
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf147180)
+{
+    // load a tracked table insertion (single redline)
+    createSwDoc("tdf147180.fodt");
+    SwDoc* pDoc = getSwDoc();
+
+    // turn on red-lining and show changes
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | 
RedlineFlags::ShowDelete
+                                                      | 
RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    CPPUNIT_ASSERT_MESSAGE(
+        "redlines should be visible",
+        
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+
+    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xTables(xTextTablesSupplier->getTextTables(),
+                                                    uno::UNO_QUERY);
+    // there is a table in the text
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
+
+    // insert a character in the first cell with change tracking
+    SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Insert("x");
+
+    // reject all the changes, including table insertion
+
+    IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
+    rIDRA.AcceptAllRedline(/*bAccept=*/false);
+
+    // no table left in the text
+
+    // This was 1 (lost tracking of the table after modifying its text content)
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables->getCount());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf128335)
 {
     // Load the bugdoc, which has 3 textboxes.
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index dec4181c4846..5987667a26b3 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -25,6 +25,7 @@
 #include <tools/datetimeutils.hxx>
 #include <hintids.hxx>
 #include <svl/itemiter.hxx>
+#include <editeng/prntitem.hxx>
 #include <comphelper/lok.hxx>
 #include <comphelper/string.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
@@ -593,6 +594,19 @@ bool 
SwRedlineTable::InsertWithValidRanges(SwRangeRedline*& p, size_type* pInsPo
         auto pTmpRedline = pRedline.release();
         if (Insert(pTmpRedline, nInsPos))
         {
+            // tdf#147180 set table tracking to the table row
+            // TODO handle also empty rows
+            SwDoc& rDoc = pTmpRedline->GetDoc();
+            if ( rDoc.GetIDocumentUndoRedo().DoesUndo() &&
+                 pTmpRedline->GetPointNode().GetTableBox() )
+            {
+                SvxPrintItem aSetTracking(RES_PRINT, false);
+                SwNodeIndex aInsPos( 
*(pTmpRedline->GetPointNode().GetTableBox()->GetSttNd()), 1);
+                SwCursor aCursor( SwPosition(aInsPos), nullptr );
+                ::sw::UndoGuard const 
undoGuard(pTmpRedline->GetDoc().GetIDocumentUndoRedo());
+                rDoc.SetRowNotTracked( aCursor, aSetTracking );
+            }
+
             pTmpRedline->CallDisplayFunc(nInsPos);
             bAnyIns = true;
             if (pInsPos && *pInsPos < nInsPos)

Reply via email to