tdf#61154 sw Table of Contents: remove tracked deletion

... part of a chapter, section etc. names also in Show
Changes mode, instead of showing as normal text.

Note: This problem was worse, then the case of references,
because hiding tracked changes didn't fix the Table of
Contents automatically, so it's better to avoid the
generation of the bad mixed names, which showed also
the deleted text as normal, without any visible differences
(strikethrough etc.).

Change-Id: Ieef8cf6e2f8bef64f99e5cb0542b7b43d8e76a27
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107176
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sw/qa/extras/uiwriter/data3/tdf61154.fodt b/sw/qa/extras/uiwriter/data3/tdf61154.fodt
new file mode 100644
index 0000000..18e0c0a
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data3/tdf61154.fodt
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office: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:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:officeooo="http://openoffice.org/2009/office" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text" xmlns:dc="http://purl.org/dc/elements/1.1/">
 <office:styles>
  <style:style style:name="Standard" style:family="paragraph" style:class="text"/>
  <style:default-style style:family="paragraph">
   <style:text-properties fo:language="en" fo:country="US"/>
  </style:default-style>
 </office:styles>
 <office:body>
  <office:text>
   <text:tracked-changes text:track-changes="false">
    <text:changed-region xml:id="ct94620665978512" text:id="ct94620665978512">
     <text:insertion>
      <office:change-info>
       <dc:creator>X</dc:creator>
       <dc:date>2020-12-03</dc:date>
      </office:change-info>
     </text:insertion>
    </text:changed-region>
    <text:changed-region xml:id="ct94620665981936" text:id="ct94620665981936">
     <text:deletion>
      <office:change-info>
       <dc:creator>X</dc:creator>
       <dc:date>2020-12-03</dc:date>
      </office:change-info>
     </text:deletion>
    </text:changed-region>
    <text:changed-region xml:id="ct94620665960832" text:id="ct94620665960832">
     <text:deletion>
      <office:change-info>
       <dc:creator>X</dc:creator>
       <dc:date>2020-12-03</dc:date>
      </office:change-info>
     </text:deletion>
    </text:changed-region>
   </text:tracked-changes>
   <text:p text:style-name="Standard"/>
   <text:table-of-content text:style-name="Sect1" text:protected="true" text:name="Table of Contents1">
    <text:table-of-content-source text:outline-level="10">
     <text:index-title-template text:style-name="Contents_20_Heading">Table of Contents</text:index-title-template>
     <text:table-of-content-entry-template text:outline-level="1" text:style-name="Contents_20_1">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
     <text:table-of-content-entry-template text:outline-level="2" text:style-name="Contents_20_2">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
     <text:table-of-content-entry-template text:outline-level="3" text:style-name="Contents_20_3">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
     <text:table-of-content-entry-template text:outline-level="4" text:style-name="Contents_20_4">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
     <text:table-of-content-entry-template text:outline-level="5" text:style-name="Contents_20_5">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
     <text:table-of-content-entry-template text:outline-level="6" text:style-name="Contents_20_6">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
     <text:table-of-content-entry-template text:outline-level="7" text:style-name="Contents_20_7">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
     <text:table-of-content-entry-template text:outline-level="8" text:style-name="Contents_20_8">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
     <text:table-of-content-entry-template text:outline-level="9" text:style-name="Contents_20_9">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
     <text:table-of-content-entry-template text:outline-level="10" text:style-name="Contents_20_10">
      <text:index-entry-link-start text:style-name="Index_20_Link"/>
      <text:index-entry-chapter/>
      <text:index-entry-text/>
      <text:index-entry-tab-stop style:type="right" style:leader-char="."/>
      <text:index-entry-page-number/>
      <text:index-entry-link-end/>
     </text:table-of-content-entry-template>
    </text:table-of-content-source>
    <text:index-body>
     <text:index-title text:style-name="Sect1" text:name="Table of Contents1_Head">
      <text:p text:style-name="Contents_20_Heading">Table of Contents</text:p>
     </text:index-title>
     <text:p text:style-name="P1"><text:a xlink:type="simple" xlink:href="#__RefHeading__5574_1973640051" text:style-name="Index_20_Link" text:visited-style-name="Index_20_Link">Update me!<text:tab/>1</text:a></text:p>
    </text:index-body>
   </text:table-of-content>
   <text:h text:style-name="Heading_20_1" text:outline-level="1"><text:bookmark-start text:name="__RefHeading__5574_1973640051"/>Text <text:change-start text:change-id="ct94620665978512"/>Inserted<text:change-end text:change-id="ct94620665978512"/><text:change-start text:change-id="ct94620665981936"/>D<text:change-end text:change-id="ct94620665981936"/><text:change-start text:change-id="ct94620665960832"/>eleted<text:bookmark-end text:name="__RefHeading__5574_1973640051"/><text:change-end text:change-id="ct94620665960832"/></text:h>
  </office:text>
 </office:body>
</office:document>
diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx
index baca0e6..d5f57f0 100644
--- a/sw/qa/extras/uiwriter/uiwriter3.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter3.cxx
@@ -33,6 +33,8 @@
#include <drawdoc.hxx>
#include <dcontact.hxx>
#include <svx/svdpage.hxx>
#include <ndtxt.hxx>
#include <IDocumentRedlineAccess.hxx>

namespace
{
@@ -218,6 +220,40 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf132911)
    //CPPUNIT_ASSERT_EQUAL(4, getShapes());
}

CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf61154)
{
    load(DATA_DIRECTORY, "tdf61154.fodt");
    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
    CPPUNIT_ASSERT(pTextDoc);

    SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
    CPPUNIT_ASSERT(pWrtShell);

    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();

    pWrtShell->GotoNextTOXBase();

    // show changes
    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowDelete
                                                      | RedlineFlags::ShowInsert);
    CPPUNIT_ASSERT_MESSAGE("redlining should be off",
                           !pDoc->getIDocumentRedlineAccess().IsRedlineOn());
    CPPUNIT_ASSERT_MESSAGE(
        "redlines should be visible",
        IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));

    const SwTOXBase* pTOXBase = pWrtShell->GetCurTOX();
    pWrtShell->UpdateTableOf(*pTOXBase);
    SwCursorShell* pShell(pDoc->GetEditShell());
    SwTextNode* pTitleNode = pShell->GetCursor()->GetNode().GetTextNode();
    SwNodeIndex aIdx(*pTitleNode);

    // table of contents node shouldn't contain tracked deletion
    // This was "Text InsertedDeleted\t1"
    SwTextNode* pNext = static_cast<SwTextNode*>(pDoc->GetNodes().GoNext(&aIdx));
    CPPUNIT_ASSERT_EQUAL(OUString("Text Inserted\t1"), pNext->GetText());
}

CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf134404)
{
    load(DATA_DIRECTORY, "tdf134404.odt");
diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx
index 962c6ed..87e5874 100644
--- a/sw/source/core/tox/txmsrt.cxx
+++ b/sw/source/core/tox/txmsrt.cxx
@@ -551,7 +551,7 @@ TextAndReading SwTOXPara::GetText_Impl(SwRootFrame const*const pLayout) const
            assert(nEndIndex == -1);
            return TextAndReading(sw::GetExpandTextMerged(
                        pLayout, *static_cast<const SwTextNode*>(pNd),
                        false, false, ExpandMode(0)),
                        false, false, ExpandMode::HideDeletions),
                    OUString());
        }
        break;