[Libreoffice-commits] core.git: sw/inc sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Dec 21 21:13:51 UTC 2018


 sw/inc/ToxTextGenerator.hxx             |   25 ++++-
 sw/inc/doc.hxx                          |    8 +
 sw/inc/tox.hxx                          |    3 
 sw/qa/core/test_ToxTextGenerator.cxx    |   14 +-
 sw/source/core/doc/doc.cxx              |    5 -
 sw/source/core/doc/doctxm.cxx           |  157 ++++++++++++++++++++------------
 sw/source/core/edit/edtox.cxx           |    6 -
 sw/source/core/fields/reffld.cxx        |   21 ++--
 sw/source/core/inc/doctxm.hxx           |   22 +++-
 sw/source/core/inc/txmsrt.hxx           |   54 ++++++-----
 sw/source/core/inc/txtfrm.hxx           |    3 
 sw/source/core/tox/ToxTextGenerator.cxx |  149 ++++++++++++++++++++++--------
 sw/source/core/tox/tox.cxx              |    4 
 sw/source/core/tox/txmsrt.cxx           |  147 +++++++++++++++++++++++------
 sw/source/core/unocore/unoidx.cxx       |    5 -
 sw/source/ui/index/multmrk.cxx          |    3 
 sw/source/ui/index/swuiidxmrk.cxx       |    9 +
 sw/source/uibase/inc/toxmgr.hxx         |    1 
 sw/source/uibase/index/toxmgr.cxx       |    2 
 19 files changed, 446 insertions(+), 192 deletions(-)

New commits:
commit 80cedb5dcb6a7dd6c01349b93fab49ecee5f6594
Author:     Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Dec 21 11:56:30 2018 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Fri Dec 21 22:13:23 2018 +0100

    sw_redlinehide: adapt ToX Update
    
    The ToX exists only once in the model, so it either has to have the
    content corresponding to redlines being shown, or hidden.
    
    Adapt Update based on current layout setting.
    
    Change-Id: Ibf5ec092632cf3a5f513965afdb840fd8239a7fd
    Reviewed-on: https://gerrit.libreoffice.org/65527
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>

diff --git a/sw/inc/ToxTextGenerator.hxx b/sw/inc/ToxTextGenerator.hxx
index 6540843f086b..91eac53d3c36 100644
--- a/sw/inc/ToxTextGenerator.hxx
+++ b/sw/inc/ToxTextGenerator.hxx
@@ -32,6 +32,7 @@ class SwFormatAutoFormat;
 class SwChapterField;
 class SwChapterFieldType;
 class SwContentFrame;
+class SwRootFrame;
 class SwContentNode;
 class SwDoc;
 class SwForm;
@@ -45,6 +46,7 @@ namespace sw {
 
 class ToxLinkProcessor;
 class ToxTabStopTokenHandler;
+class ToxWhitespaceStripper;
 
 /** This class generates text for the entries of a table of x.
  *
@@ -64,7 +66,8 @@ public:
      */
     void
     GenerateText(SwDoc *doc, const std::vector<std::unique_ptr<SwTOXSortTabBase>>& entries,
-                      sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess);
+        sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess,
+        SwRootFrame const* pLayout);
 
 private:
     const SwForm& mToxForm;
@@ -80,13 +83,23 @@ private:
         std::vector<sal_Int32> startPositions;
         std::vector<sal_Int32> endPositions;
     };
+
+    static void GetAttributesForNode(
+        HandledTextToken & rResult,
+        sal_Int32 & rOffset,
+        SwTextNode const& rNode,
+        ToxWhitespaceStripper const& rStripper,
+        SwAttrPool & rPool,
+        SwRootFrame const*const pLayout);
+
     /** Append text (and selected attributes) to a target node.
      *
      * Will take the text of @p source, and return the text and the attributes which should be added to the
      * target text node. @see CollectAttributesForTox() for the criteria of the attributes which are taken.
      */
     static HandledTextToken
-    HandleTextToken(const SwTOXSortTabBase& source, SwAttrPool& attrPool);
+    HandleTextToken(const SwTOXSortTabBase& source, SwAttrPool& attrPool,
+            SwRootFrame const*const pLayout);
 
     /** Applies the result of a handled text token to a target node. */
     static void
@@ -124,18 +137,20 @@ private:
      * for details.
      */
     static OUString
-    GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase, bool bUsePrefix, sal_uInt8 nLevel);
+    GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase, bool bUsePrefix,
+            sal_uInt8 nLevel, SwRootFrame const* pLayout);
 
     /** Handle a chapter token.
      */
     OUString
-    HandleChapterToken(const SwTOXSortTabBase& rBase, const SwFormToken& aToken, SwDoc* pDoc) const;
+    HandleChapterToken(const SwTOXSortTabBase& rBase, const SwFormToken& aToken,
+            SwRootFrame const* pLayout) const;
 
     /** Generate the text for a chapter token.
      */
     OUString
     GenerateTextForChapterToken(const SwFormToken& chapterToken, const SwContentFrame* contentFrame,
-            const SwContentNode *contentNode) const;
+            const SwContentNode *contentNode, SwRootFrame const* pLayout) const;
 
     /** Obtain a ChapterField to use for the text generation.
      * @internal
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 30e38908c72d..452a7aa214de 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -915,7 +915,8 @@ public:
     SwTOXBaseSection* InsertTableOf( const SwPosition& rPos,
                                             const SwTOXBase& rTOX,
                                             const SfxItemSet* pSet = nullptr,
-                                            bool bExpand = false );
+                                            bool bExpand = false,
+                                    SwRootFrame const* pLayout = nullptr);
     void              InsertTableOf( sal_uLong nSttNd, sal_uLong nEndNd,
                                             const SwTOXBase& rTOX,
                                             const SfxItemSet* pSet );
@@ -961,7 +962,8 @@ public:
     void                SetDefaultTOXBase(const SwTOXBase& rBase);
 
     // Key for management of index.
-    void GetTOIKeys( SwTOIKeyType eTyp, std::vector<OUString>& rArr ) const;
+    void GetTOIKeys(SwTOIKeyType eTyp, std::vector<OUString>& rArr,
+            SwRootFrame const& rLayout) const;
 
     // Sort table text.
     bool SortTable(const SwSelBoxes& rBoxes, const SwSortOptions&);
@@ -1546,7 +1548,7 @@ public:
                    bool bBroadcast = false);
 
     // Change a TOX undoable.
-    void ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew);
+    void ChangeTOX(SwTOXBase & rTOX, const SwTOXBase & rNew, SwRootFrame const& rLayout);
 
     /**
        Returns a textual description of a PaM.
diff --git a/sw/inc/tox.hxx b/sw/inc/tox.hxx
index e5c938e4e34e..ae5a75df26d6 100644
--- a/sw/inc/tox.hxx
+++ b/sw/inc/tox.hxx
@@ -41,6 +41,7 @@ class SwTOXType;
 class SwTOXMark;
 class SwTextTOXMark;
 class SwDoc;
+class SwRootFrame;
 
 typedef std::vector<SwTOXMark*> SwTOXMarks;
 
@@ -98,7 +99,7 @@ public:
 
     void InvalidateTOXMark();
 
-    OUString                GetText() const;
+    OUString                GetText(SwRootFrame const* pLayout) const;
 
     inline bool             IsAlternativeText() const;
     inline const OUString&  GetAlternativeText() const;
diff --git a/sw/qa/core/test_ToxTextGenerator.cxx b/sw/qa/core/test_ToxTextGenerator.cxx
index 3ddc9fef6f80..25304a382ed3 100644
--- a/sw/qa/core/test_ToxTextGenerator.cxx
+++ b/sw/qa/core/test_ToxTextGenerator.cxx
@@ -50,7 +50,7 @@ struct MockedSortTab : public SwTOXSortTabBase {
     MockedSortTab()
     : SwTOXSortTabBase(TOX_SORT_INDEX,nullptr,nullptr,nullptr) {}
 
-    virtual TextAndReading GetText_Impl() const override {
+    virtual TextAndReading GetText_Impl(SwRootFrame const*) const override {
         return TextAndReading();
     }
     virtual sal_uInt16  GetLevel() const override {
@@ -89,7 +89,7 @@ ToxTextGeneratorTest::EmptyStringIsReturnedAsNumStringIfNoTextMarkIsSet()
     sortTab.pTextMark = nullptr;
 
     OUString const expected("");
-    OUString actual = ToxTextGenerator::GetNumStringOfFirstNode(sortTab, false, 0);
+    OUString actual = ToxTextGenerator::GetNumStringOfFirstNode(sortTab, false, 0, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 }
 
@@ -100,7 +100,7 @@ ToxTextGeneratorTest::EmptyStringIsReturnedAsNumStringIfToxSourcesIsEmpty()
     sortTab.pTextMark = reinterpret_cast<SwTextTOXMark*>(1);
 
     OUString const expected("");
-    OUString actual = ToxTextGenerator::GetNumStringOfFirstNode(sortTab, false, 0);
+    OUString actual = ToxTextGenerator::GetNumStringOfFirstNode(sortTab, false, 0, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 }
 
@@ -150,13 +150,13 @@ ToxTextGeneratorTest::ChapterNumberWithoutTextIsGeneratedForNoprepstTitle()
     token.nChapterFormat = CF_NUM_NOPREPST_TITLE;
 
     OUString expected("1");
-    OUString actual = ttg.GenerateTextForChapterToken(token, nullptr, nullptr);
+    OUString actual = ttg.GenerateTextForChapterToken(token, nullptr, nullptr, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 
     // we cannot mock the pre- and suffix generation in the chapterfield. We just test that sNumber and
     // sTitle are used and hope that the pre- and suffix addition works.
     token.nChapterFormat = CF_NUMBER;
-    expected = ttg.GenerateTextForChapterToken(token, nullptr, nullptr);
+    expected = ttg.GenerateTextForChapterToken(token, nullptr, nullptr, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 }
 
@@ -176,13 +176,13 @@ ToxTextGeneratorTest::ChapterNumberWithTitleIsGeneratedForNumberNoPrepst()
     token.nChapterFormat = CF_NUMBER_NOPREPST;
 
     OUString expected("5 myTitle");
-    OUString actual = ttg.GenerateTextForChapterToken(token, nullptr, nullptr);
+    OUString actual = ttg.GenerateTextForChapterToken(token, nullptr, nullptr, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 
     // we cannot mock the pre- and suffix generation in the chapterfield. We just test that sNumber and
     // sTitle are used and hope that the pre- and suffix addition works.
     token.nChapterFormat = CF_NUM_TITLE;
-    expected = ttg.GenerateTextForChapterToken(token, nullptr, nullptr);
+    expected = ttg.GenerateTextForChapterToken(token, nullptr, nullptr, nullptr);
     CPPUNIT_ASSERT_EQUAL(expected, actual);
 }
 
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 9561462349f4..1e223e8b64a9 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1726,7 +1726,8 @@ void SwDoc::AppendUndoForInsertFromDB( const SwPaM& rPam, bool bIsTable )
     }
 }
 
-void SwDoc::ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew)
+void SwDoc::ChangeTOX(SwTOXBase & rTOX, const SwTOXBase & rNew,
+        SwRootFrame const& rLayout)
 {
     if (GetIDocumentUndoRedo().DoesUndo())
     {
@@ -1740,7 +1741,7 @@ void SwDoc::ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew)
 
     if (dynamic_cast<const SwTOXBaseSection*>( &rTOX) !=  nullptr)
     {
-        static_cast<SwTOXBaseSection &>(rTOX).Update();
+        static_cast<SwTOXBaseSection &>(rTOX).Update(nullptr, &rLayout);
         static_cast<SwTOXBaseSection &>(rTOX).UpdatePageNum();
     }
 }
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 1c90d05ee8b3..4e7ab4507e06 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -79,8 +79,17 @@
 
 using namespace ::com::sun::star;
 
+template<typename T, typename... Args> static
+typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
+MakeSwTOXSortTabBase(SwRootFrame const*const pLayout, Args&& ... args)
+{
+    std::unique_ptr<T> pRet(new T(std::forward<Args>(args)...));
+    pRet->InitText(pLayout); // ensure it's expanded with the layout
+    return pRet;
+}
 
-void SwDoc::GetTOIKeys( SwTOIKeyType eTyp, std::vector<OUString>& rArr ) const
+void SwDoc::GetTOIKeys(SwTOIKeyType eTyp, std::vector<OUString>& rArr,
+        SwRootFrame const& rLayout) const
 {
     rArr.clear();
 
@@ -96,7 +105,9 @@ void SwDoc::GetTOIKeys( SwTOIKeyType eTyp, std::vector<OUString>& rArr ) const
             continue;
         const SwTextTOXMark* pMark = pItem->GetTextTOXMark();
         if ( pMark && pMark->GetpTextNd() &&
-             pMark->GetpTextNd()->GetNodes().IsDocNodes() )
+             pMark->GetpTextNd()->GetNodes().IsDocNodes() &&
+             (!rLayout.IsHideRedlines()
+                || !sw::IsMarkHintHidden(rLayout, *pMark->GetpTextNd(), *pMark)))
         {
             const OUString sStr = TOI_PRIMARY == eTyp
                 ? pItem->GetPrimaryKey()
@@ -268,7 +279,7 @@ const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark,
             // possible to also travel across Entries on the same (!)
             // position. If someone has time, please feel free to optimize.
             case TOX_SAME_PRV:
-                if( pTOXMark->GetText() != rCurTOXMark.GetText() )
+                if (pTOXMark->GetText(nullptr) != rCurTOXMark.GetText(nullptr))
                     break;
                 [[fallthrough]];
             case TOX_PRV:
@@ -290,7 +301,7 @@ const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark,
                 break;
 
             case TOX_SAME_NXT:
-                if( pTOXMark->GetText() != rCurTOXMark.GetText() )
+                if (pTOXMark->GetText(nullptr) != rCurTOXMark.GetText(nullptr))
                     break;
                 [[fallthrough]];
             case TOX_NXT:
@@ -338,7 +349,8 @@ const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark,
 SwTOXBaseSection* SwDoc::InsertTableOf( const SwPosition& rPos,
                                                 const SwTOXBase& rTOX,
                                                 const SfxItemSet* pSet,
-                                                bool bExpand )
+                                                bool bExpand,
+                                        SwRootFrame const*const pLayout)
 {
     GetIDocumentUndoRedo().StartUndo( SwUndoId::INSTOX, nullptr );
 
@@ -357,7 +369,7 @@ SwTOXBaseSection* SwDoc::InsertTableOf( const SwPosition& rPos,
             // add value for 2nd parameter = true to
             // indicate, that a creation of a new table of content has to be performed.
             // Value of 1st parameter = default value.
-            pNewSection->Update( nullptr, true );
+            pNewSection->Update( nullptr, pLayout, true );
         }
         else if( rTOX.GetTitle().getLength()==1 && IsInReading() )
         // insert title of TOX
@@ -694,7 +706,8 @@ bool SwDoc::SetTOXBaseName(const SwTOXBase& rTOXBase, const OUString& rName)
     return false;
 }
 
-static const SwTextNode* lcl_FindChapterNode( const SwNode& rNd, sal_uInt8 nLvl = 0 )
+static const SwTextNode* lcl_FindChapterNode( const SwNode& rNd,
+        SwRootFrame const*const pLayout, sal_uInt8 const nLvl = 0 )
 {
     const SwNode* pNd = &rNd;
     if( pNd->GetNodes().GetEndOfExtras().GetIndex() > pNd->GetIndex() )
@@ -711,7 +724,7 @@ static const SwTextNode* lcl_FindChapterNode( const SwNode& rNd, sal_uInt8 nLvl
             OSL_ENSURE( pNd, "Where's the paragraph?" );
         }
     }
-    return pNd ? pNd->FindOutlineNodeOfLevel( nLvl ) : nullptr;
+    return pNd ? pNd->FindOutlineNodeOfLevel(nLvl, pLayout) : nullptr;
 }
 
 // Table of contents class
@@ -743,7 +756,8 @@ bool SwTOXBaseSection::SetPosAtStartEnd( SwPosition& rPos ) const
 
 /// Collect table of contents content
 void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
-                              const bool        _bNewTOX )
+                              SwRootFrame const*const pLayout,
+                              const bool        _bNewTOX)
 {
     if (!SwTOXBase::GetRegisteredIn()->HasWriterListeners() ||
         !GetFormat())
@@ -753,7 +767,8 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     SwSectionNode const*const pSectNd(GetFormat()->GetSectionNode());
     if (nullptr == pSectNd ||
         !pSectNd->GetNodes().IsDocNodes() ||
-        IsHiddenFlag() )
+        IsHiddenFlag() ||
+        (pLayout->IsHideRedlines() && pSectNd->GetRedlineMergeFlag() == SwNode::Merge::Hidden))
     {
         return;
     }
@@ -837,7 +852,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     // find the first layout node for this TOX, if it only find the content
     // in his own chapter
     const SwTextNode* pOwnChapterNode = IsFromChapter()
-            ? ::lcl_FindChapterNode( *pSectNd )
+            ? ::lcl_FindChapterNode( *pSectNd, pLayout )
             : nullptr;
 
     SwNode2LayoutSaveUpperFrames aN2L(*pSectNd);
@@ -901,36 +916,36 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
     pDoc->UpdateNumRule();
 
     if( GetCreateType() & SwTOXElement::Mark )
-        UpdateMarks( aIntl, pOwnChapterNode );
+        UpdateMarks( aIntl, pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::OutlineLevel )
-        UpdateOutline( pOwnChapterNode );
+        UpdateOutline( pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Template )
-        UpdateTemplate( pOwnChapterNode );
+        UpdateTemplate( pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Ole ||
             TOX_OBJECTS == SwTOXBase::GetType())
-        UpdateContent( SwTOXElement::Ole, pOwnChapterNode );
+        UpdateContent( SwTOXElement::Ole, pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Table ||
             (TOX_TABLES == SwTOXBase::GetType() && IsFromObjectNames()) )
-        UpdateTable( pOwnChapterNode );
+        UpdateTable( pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Graphic ||
         (TOX_ILLUSTRATIONS == SwTOXBase::GetType() && IsFromObjectNames()))
-        UpdateContent( SwTOXElement::Graphic, pOwnChapterNode );
+        UpdateContent( SwTOXElement::Graphic, pOwnChapterNode, pLayout );
 
     if( !GetSequenceName().isEmpty() && !IsFromObjectNames() &&
         (TOX_TABLES == SwTOXBase::GetType() ||
          TOX_ILLUSTRATIONS == SwTOXBase::GetType() ) )
-        UpdateSequence( pOwnChapterNode );
+        UpdateSequence( pOwnChapterNode, pLayout );
 
     if( GetCreateType() & SwTOXElement::Frame )
-        UpdateContent( SwTOXElement::Frame, pOwnChapterNode );
+        UpdateContent( SwTOXElement::Frame, pOwnChapterNode, pLayout );
 
     if(TOX_AUTHORITIES == SwTOXBase::GetType())
-        UpdateAuthorities( aIntl );
+        UpdateAuthorities( aIntl, pLayout );
 
     // Insert AlphaDelimitters if needed (just for keywords)
     if( TOX_INDEX == SwTOXBase::GetType() &&
@@ -987,7 +1002,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
                                 sw::DefaultToxTabStopTokenHandler::TABSTOPS_RELATIVE_TO_INDENT :
                                 sw::DefaultToxTabStopTokenHandler::TABSTOPS_RELATIVE_TO_PAGE);
         sw::ToxTextGenerator ttgn(GetTOXForm(), tabStopTokenHandler);
-        ttgn.GenerateText(GetFormat()->GetDoc(), m_aSortArr, nCnt, nRange);
+        ttgn.GenerateText(GetFormat()->GetDoc(), m_aSortArr, nCnt, nRange, pLayout);
         nCnt += nRange - 1;
     }
 
@@ -1054,7 +1069,9 @@ void SwTOXBaseSection::InsertAlphaDelimitter( const SwTOXInternational& rIntl )
             // We skip all that are less than a small Blank (these are special characters)
             if( ' ' <= sDeli[0] )
             {
-                std::unique_ptr<SwTOXCustom> pCst(new SwTOXCustom( TextAndReading(sDeli, OUString()),
+                std::unique_ptr<SwTOXCustom> pCst(
+                        MakeSwTOXSortTabBase<SwTOXCustom>(nullptr,
+                                TextAndReading(sDeli, OUString()),
                                                      FORM_ALPHA_DELIMITTER,
                                                      rIntl, m_aSortArr[i]->GetLocale() ));
                 m_aSortArr.insert( m_aSortArr.begin() + i, std::move(pCst));
@@ -1122,7 +1139,8 @@ SwTextFormatColl* SwTOXBaseSection::GetTextFormatColl( sal_uInt16 nLevel )
 
 /// Create from Marks
 void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
-                                    const SwTextNode* pOwnChapterNode )
+                                    const SwTextNode* pOwnChapterNode,
+                                    SwRootFrame const*const pLayout)
 {
     const SwTOXType* pType = static_cast<SwTOXType*>( SwTOXBase::GetRegisteredIn() );
     if( !pType->HasWriterListeners() )
@@ -1149,9 +1167,11 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
             if( pTOXSrc->GetNodes().IsDocNodes() &&
                 pTOXSrc->GetText().getLength() && pTOXSrc->HasWriterListeners() &&
                 pTOXSrc->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) &&
-               (!IsFromChapter() || ::lcl_FindChapterNode( *pTOXSrc ) == pOwnChapterNode ) &&
+               (!IsFromChapter() || ::lcl_FindChapterNode(*pTOXSrc, pLayout) == pOwnChapterNode) &&
                !pTOXSrc->IsHiddenByParaField() &&
-               !SwScriptInfo::IsInHiddenRange( *pTOXSrc, pTextMark->GetStart() ) )
+               !SwScriptInfo::IsInHiddenRange(*pTOXSrc, pTextMark->GetStart()) &&
+               (!pLayout || !pLayout->IsHideRedlines()
+                    || !sw::IsMarkHintHidden(*pLayout, *pTOXSrc, *pTextMark)))
             {
                 if(TOX_INDEX == eTOXTyp)
                 {
@@ -1159,16 +1179,16 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
                     assert(g_pBreakIt);
                     lang::Locale aLocale = g_pBreakIt->GetLocale(pTOXSrc->GetLang(pTextMark->GetStart()));
 
-                    InsertSorted(o3tl::make_unique<SwTOXIndex>( *pTOXSrc, pTextMark,
+                    InsertSorted(MakeSwTOXSortTabBase<SwTOXIndex>(pLayout, *pTOXSrc, pTextMark,
                                             GetOptions(), FORM_ENTRY, rIntl, aLocale ));
                     if(GetOptions() & SwTOIOptions::KeyAsEntry &&
                         !pTextMark->GetTOXMark().GetPrimaryKey().isEmpty())
                     {
-                        InsertSorted(o3tl::make_unique<SwTOXIndex>( *pTOXSrc, pTextMark,
+                        InsertSorted(MakeSwTOXSortTabBase<SwTOXIndex>(pLayout, *pTOXSrc, pTextMark,
                                                 GetOptions(), FORM_PRIMARY_KEY, rIntl, aLocale ));
                         if (!pTextMark->GetTOXMark().GetSecondaryKey().isEmpty())
                         {
-                            InsertSorted(o3tl::make_unique<SwTOXIndex>( *pTOXSrc, pTextMark,
+                            InsertSorted(MakeSwTOXSortTabBase<SwTOXIndex>(pLayout, *pTOXSrc, pTextMark,
                                                     GetOptions(), FORM_SECONDARY_KEY, rIntl, aLocale ));
                         }
                     }
@@ -1177,7 +1197,7 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
                     pMark->GetLevel() <= GetLevel())
                 {   // table of content mark
                     // also used for user marks
-                    InsertSorted(o3tl::make_unique<SwTOXContent>( *pTOXSrc, pTextMark, rIntl ));
+                    InsertSorted(MakeSwTOXSortTabBase<SwTOXContent>(pLayout, *pTOXSrc, pTextMark, rIntl));
                 }
             }
         }
@@ -1185,7 +1205,8 @@ void SwTOXBaseSection::UpdateMarks( const SwTOXInternational& rIntl,
 }
 
 /// Generate table of contents from outline
-void SwTOXBaseSection::UpdateOutline( const SwTextNode* pOwnChapterNode )
+void SwTOXBaseSection::UpdateOutline( const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwNodes& rNds = pDoc->GetNodes();
@@ -1197,19 +1218,22 @@ void SwTOXBaseSection::UpdateOutline( const SwTextNode* pOwnChapterNode )
         SwTextNode* pTextNd = pOutlineNode->GetTextNode();
         if( pTextNd && pTextNd->Len() && pTextNd->HasWriterListeners() &&
             sal_uInt16( pTextNd->GetAttrOutlineLevel()) <= GetLevel() &&
-            pTextNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) &&
+            pTextNd->getLayoutFrame(pLayout) &&
            !pTextNd->IsHiddenByParaField() &&
            !pTextNd->HasHiddenCharAttribute( true ) &&
+           (!pLayout || !pLayout->IsHideRedlines()
+                || static_cast<SwTextFrame*>(pTextNd->getLayoutFrame(pLayout))->GetTextNodeForParaProps() == pTextNd) &&
             ( !IsFromChapter() ||
-               ::lcl_FindChapterNode( *pTextNd ) == pOwnChapterNode ))
+               ::lcl_FindChapterNode(*pTextNd, pLayout) == pOwnChapterNode ))
         {
-            InsertSorted( o3tl::make_unique<SwTOXPara>( *pTextNd, SwTOXElement::OutlineLevel ) );
+            InsertSorted(MakeSwTOXSortTabBase<SwTOXPara>(pLayout, *pTextNd, SwTOXElement::OutlineLevel));
         }
     }
 }
 
 /// Generate table of contents from template areas
-void SwTOXBaseSection::UpdateTemplate( const SwTextNode* pOwnChapterNode )
+void SwTOXBaseSection::UpdateTemplate(const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
@@ -1236,12 +1260,14 @@ void SwTOXBaseSection::UpdateTemplate( const SwTextNode* pOwnChapterNode )
                 ::SetProgressState( 0, pDoc->GetDocShell() );
 
                 if (pTextNd->GetText().getLength() &&
-                    pTextNd->getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout()) &&
+                    pTextNd->getLayoutFrame(pLayout) &&
                     pTextNd->GetNodes().IsDocNodes() &&
-                    ( !IsFromChapter() || pOwnChapterNode ==
-                        ::lcl_FindChapterNode( *pTextNd ) ) )
+                    (!pLayout || !pLayout->IsHideRedlines()
+                        || static_cast<SwTextFrame*>(pTextNd->getLayoutFrame(pLayout))->GetTextNodeForParaProps() == pTextNd) &&
+                    (!IsFromChapter() || pOwnChapterNode ==
+                        ::lcl_FindChapterNode(*pTextNd, pLayout)))
                 {
-                    InsertSorted( o3tl::make_unique<SwTOXPara>( *pTextNd, SwTOXElement::Template, i + 1 ) );
+                    InsertSorted(MakeSwTOXSortTabBase<SwTOXPara>(pLayout, *pTextNd, SwTOXElement::Template, i + 1));
                 }
             }
         }
@@ -1249,7 +1275,8 @@ void SwTOXBaseSection::UpdateTemplate( const SwTextNode* pOwnChapterNode )
 }
 
 /// Generate content from sequence fields
-void SwTOXBaseSection::UpdateSequence( const SwTextNode* pOwnChapterNode )
+void SwTOXBaseSection::UpdateSequence(const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwFieldType* pSeqField = pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::SetExp, GetSequenceName(), false);
@@ -1266,10 +1293,12 @@ void SwTOXBaseSection::UpdateSequence( const SwTextNode* pOwnChapterNode )
         ::SetProgressState( 0, pDoc->GetDocShell() );
 
         if (rTextNode.GetText().getLength() &&
-            rTextNode.getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout()) &&
+            rTextNode.getLayoutFrame(pLayout) &&
             rTextNode.GetNodes().IsDocNodes() &&
             ( !IsFromChapter() ||
-                ::lcl_FindChapterNode( rTextNode ) == pOwnChapterNode ) )
+                ::lcl_FindChapterNode(rTextNode, pLayout) == pOwnChapterNode)
+            && (!pLayout || !pLayout->IsHideRedlines()
+                || !sw::IsFieldDeletedInModel(pDoc->getIDocumentRedlineAccess(), *pTextField)))
         {
             const SwSetExpField& rSeqField = dynamic_cast<const SwSetExpField&>(*(pFormatField->GetField()));
             const OUString sName = GetSequenceName()
@@ -1286,12 +1315,14 @@ void SwTOXBaseSection::UpdateSequence( const SwTextNode* pOwnChapterNode )
             {
                 pNew->SetEndIndex(pTextField->GetStart() + 1);
             }
+            pNew->InitText(pLayout);
             InsertSorted(std::move(pNew));
         }
     }
 }
 
-void SwTOXBaseSection::UpdateAuthorities( const SwTOXInternational& rIntl )
+void SwTOXBaseSection::UpdateAuthorities(const SwTOXInternational& rIntl,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwFieldType* pAuthField = pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::TableOfAuthorities, OUString(), false);
@@ -1309,11 +1340,13 @@ void SwTOXBaseSection::UpdateAuthorities( const SwTOXInternational& rIntl )
         ::SetProgressState( 0, pDoc->GetDocShell() );
 
         if (rTextNode.GetText().getLength() &&
-            rTextNode.getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout()) &&
-            rTextNode.GetNodes().IsDocNodes() )
+            rTextNode.getLayoutFrame(pLayout) &&
+            rTextNode.GetNodes().IsDocNodes()
+            && (!pLayout || !pLayout->IsHideRedlines()
+                || !sw::IsFieldDeletedInModel(pDoc->getIDocumentRedlineAccess(), *pTextField)))
         {
             //#106485# the body node has to be used!
-            SwContentFrame *pFrame = rTextNode.getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() );
+            SwContentFrame *const pFrame = rTextNode.getLayoutFrame(pLayout);
             SwPosition aFieldPos(rTextNode);
             const SwTextNode* pTextNode = nullptr;
             if(pFrame && !pFrame->IsInDocBody())
@@ -1321,7 +1354,7 @@ void SwTOXBaseSection::UpdateAuthorities( const SwTOXInternational& rIntl )
             if(!pTextNode)
                 pTextNode = &rTextNode;
 
-            InsertSorted(o3tl::make_unique<SwTOXAuthority>( *pTextNode, *pFormatField, rIntl ));
+            InsertSorted(MakeSwTOXSortTabBase<SwTOXAuthority>(pLayout, *pTextNode, *pFormatField, rIntl));
         }
     }
 }
@@ -1371,7 +1404,8 @@ static SwTOOElements lcl_IsSOObject( const SvGlobalName& rFactoryNm )
 }
 
 void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType,
-                                    const SwTextNode* pOwnChapterNode )
+        const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwNodes& rNds = pDoc->GetNodes();
@@ -1445,7 +1479,7 @@ void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType,
                     TOX_OBJECTS != SwTOXBase::GetType() )
             {
                 const SwTextNode* pOutlNd = ::lcl_FindChapterNode( *pCNd,
-                                                        MAXLEVEL - 1 );
+                                                pLayout, MAXLEVEL - 1);
                 if( pOutlNd )
                 {
                     if( pOutlNd->GetTextColl()->IsAssignedToListLevelOfOutlineStyle())
@@ -1455,10 +1489,14 @@ void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType,
                 }
             }
 
-            if( pCNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) && ( !IsFromChapter() ||
-                    ::lcl_FindChapterNode( *pCNd ) == pOwnChapterNode ))
+            if (pCNd->getLayoutFrame(pLayout)
+                && (!pLayout || !pLayout->IsHideRedlines()
+                    || pCNd->GetRedlineMergeFlag() != SwNode::Merge::Hidden)
+                && ( !IsFromChapter() ||
+                    ::lcl_FindChapterNode(*pCNd, pLayout) == pOwnChapterNode ))
             {
-                std::unique_ptr<SwTOXPara> pNew( new SwTOXPara( *pCNd, eMyType,
+                std::unique_ptr<SwTOXPara> pNew( MakeSwTOXSortTabBase<SwTOXPara>(
+                        pLayout, *pCNd, eMyType,
                             ( USHRT_MAX != nSetLevel )
                             ? static_cast<sal_uInt16>(nSetLevel)
                             : FORM_ALPHA_DELIMITTER ) );
@@ -1471,7 +1509,8 @@ void SwTOXBaseSection::UpdateContent( SwTOXElement eMyType,
 }
 
 /// Collect table entries
-void SwTOXBaseSection::UpdateTable( const SwTextNode* pOwnChapterNode )
+void SwTOXBaseSection::UpdateTable(const SwTextNode* pOwnChapterNode,
+        SwRootFrame const*const pLayout)
 {
     SwDoc* pDoc = GetFormat()->GetDoc();
     SwNodes& rNds = pDoc->GetNodes();
@@ -1493,14 +1532,17 @@ void SwTOXBaseSection::UpdateTable( const SwTextNode* pOwnChapterNode )
             while( nullptr != ( pCNd = rNds.GoNext( &aContentIdx ) ) &&
                 aContentIdx.GetIndex() < pTableNd->EndOfSectionIndex() )
             {
-                if( pCNd->getLayoutFrame( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) && (!IsFromChapter() ||
-                    ::lcl_FindChapterNode( *pCNd ) == pOwnChapterNode ))
+                if (pCNd->getLayoutFrame(pLayout)
+                    && (!pLayout || !pLayout->IsHideRedlines()
+                        || pCNd->GetRedlineMergeFlag() != SwNode::Merge::Hidden)
+                    && (!IsFromChapter()
+                        || ::lcl_FindChapterNode(*pCNd, pLayout) == pOwnChapterNode))
                 {
                     std::unique_ptr<SwTOXTable> pNew(new SwTOXTable( *pCNd ));
                     if( IsLevelFromChapter() && TOX_TABLES != SwTOXBase::GetType())
                     {
                         const SwTextNode* pOutlNd =
-                            ::lcl_FindChapterNode( *pCNd, MAXLEVEL - 1 );
+                            ::lcl_FindChapterNode(*pCNd, pLayout, MAXLEVEL - 1);
                         if( pOutlNd )
                         {
                             if( pOutlNd->GetTextColl()->IsAssignedToListLevelOfOutlineStyle())
@@ -1510,6 +1552,7 @@ void SwTOXBaseSection::UpdateTable( const SwTextNode* pOwnChapterNode )
                             }
                         }
                     }
+                    pNew->InitText(pLayout);
                     InsertSorted(std::move(pNew));
                     break;
                 }
@@ -1917,8 +1960,8 @@ Range SwTOXBaseSection::GetKeyRange(const OUString& rStr, const OUString& rStrRe
     }
     if(i == nMax)
     {   // If not already present, create and insert
-        std::unique_ptr<SwTOXCustom> pKey(new SwTOXCustom( aToCompare, nLevel, rIntl,
-                                             rNew.GetLocale() ));
+        std::unique_ptr<SwTOXCustom> pKey(MakeSwTOXSortTabBase<SwTOXCustom>(
+                    nullptr, aToCompare, nLevel, rIntl, rNew.GetLocale() ));
         for(i = nMin; i < nMax; ++i)
         {
             if (nLevel == m_aSortArr[i]->GetLevel() && pKey->sort_lt(*m_aSortArr[i]))
diff --git a/sw/source/core/edit/edtox.cxx b/sw/source/core/edit/edtox.cxx
index 4d4bae4af901..d7b71d352820 100644
--- a/sw/source/core/edit/edtox.cxx
+++ b/sw/source/core/edit/edtox.cxx
@@ -137,7 +137,7 @@ void SwEditShell::InsertTableOf( const SwTOXBase& rTOX, const SfxItemSet* pSet )
 
     // Insert listing
     const SwTOXBaseSection* pTOX = mxDoc->InsertTableOf(
-                                        *GetCursor()->GetPoint(), rTOX, pSet, true );
+                *GetCursor()->GetPoint(), rTOX, pSet, true, GetLayout() );
     OSL_ENSURE(pTOX, "No current TOx");
 
     // start formatting
@@ -174,7 +174,7 @@ void SwEditShell::UpdateTableOf(const SwTOXBase& rTOX, const SfxItemSet* pSet)
         pMyDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::TOXCHANGE, nullptr);
 
         // create listing stub
-        rTOXSect.Update(pSet);
+        rTOXSect.Update(pSet, GetLayout());
 
         // correct Cursor
         if( bInIndex )
@@ -215,7 +215,7 @@ const SwTOXType* SwEditShell::GetTOXType(TOXTypes eTyp, sal_uInt16 nId) const
 
 void SwEditShell::GetTOIKeys( SwTOIKeyType eTyp, std::vector<OUString>& rArr ) const
 {
-    GetDoc()->GetTOIKeys( eTyp, rArr );
+    GetDoc()->GetTOIKeys( eTyp, rArr, *GetLayout() );
 }
 
 sal_uInt16 SwEditShell::GetTOXCount() const
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index de76a4cf1641..6c015e101783 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -1104,33 +1104,37 @@ void SwGetRefFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew
     NotifyClients( pOld, pNew );
 }
 
-static bool
-IsRefMarkHidden(SwRootFrame const& rLayout, SwTextRefMark const& rRefMark)
+namespace sw {
+
+bool IsMarkHintHidden(SwRootFrame const& rLayout,
+        SwTextNode const& rNode, SwTextAttrEnd const& rHint)
 {
     if (!rLayout.IsHideRedlines())
     {
         return false;
     }
-    SwTextNode const& rNode(rRefMark.GetTextNode());
     SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
         rNode.getLayoutFrame(&rLayout)));
     if (!pFrame)
     {
         return true;
     }
-    sal_Int32 const*const pEnd(const_cast<SwTextRefMark&>(rRefMark).GetEnd());
+    sal_Int32 const*const pEnd(const_cast<SwTextAttrEnd &>(rHint).GetEnd());
     if (pEnd)
     {
-        return pFrame->MapModelToView(&rNode, rRefMark.GetStart())
+        return pFrame->MapModelToView(&rNode, rHint.GetStart())
             == pFrame->MapModelToView(&rNode, *pEnd);
     }
     else
     {
-        return pFrame->MapModelToView(&rNode, rRefMark.GetStart())
-            == pFrame->MapModelToView(&rNode, rRefMark.GetStart() + 1);
+        assert(rHint.HasDummyChar());
+        return pFrame->MapModelToView(&rNode, rHint.GetStart())
+            == pFrame->MapModelToView(&rNode, rHint.GetStart() + 1);
     }
 }
 
+} // namespace sw
+
 SwTextNode* SwGetRefFieldType::FindAnchor( SwDoc* pDoc, const OUString& rRefMark,
                                         sal_uInt16 nSubType, sal_uInt16 nSeqNo,
                                         sal_Int32* pStt, sal_Int32* pEnd,
@@ -1146,7 +1150,8 @@ SwTextNode* SwGetRefFieldType::FindAnchor( SwDoc* pDoc, const OUString& rRefMark
         {
             const SwFormatRefMark *pRef = pDoc->GetRefMark( rRefMark );
             SwTextRefMark const*const pRefMark(pRef ? pRef->GetTextRefMark() : nullptr);
-            if (pRefMark && (!pLayout || !IsRefMarkHidden(*pLayout, *pRefMark)))
+            if (pRefMark && (!pLayout || !sw::IsMarkHintHidden(*pLayout,
+                                           pRefMark->GetTextNode(), *pRefMark)))
             {
                 pTextNd = const_cast<SwTextNode*>(&pRef->GetTextRefMark()->GetTextNode());
                 *pStt = pRef->GetTextRefMark()->GetStart();
diff --git a/sw/source/core/inc/doctxm.hxx b/sw/source/core/inc/doctxm.hxx
index a23771fd70f1..59875566fa8f 100644
--- a/sw/source/core/inc/doctxm.hxx
+++ b/sw/source/core/inc/doctxm.hxx
@@ -36,14 +36,21 @@ class SwTOXBaseSection : public SwTOXBase, public SwSection
     std::vector<std::unique_ptr<SwTOXSortTabBase>> m_aSortArr;
 
     void UpdateMarks( const SwTOXInternational& rIntl,
-                      const SwTextNode* pOwnChapterNode );
-    void UpdateOutline( const SwTextNode* pOwnChapterNode );
-    void UpdateTemplate( const SwTextNode* pOwnChapterNode );
+             const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateOutline( const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateTemplate( const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
     void UpdateContent( SwTOXElement eType,
-                      const SwTextNode* pOwnChapterNode );
-    void UpdateTable( const SwTextNode* pOwnChapterNode );
-    void UpdateSequence( const SwTextNode* pOwnChapterNode );
-    void UpdateAuthorities( const SwTOXInternational& rIntl );
+             const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateTable( const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateSequence( const SwTextNode* pOwnChapterNode,
+             SwRootFrame const* pLayout );
+    void UpdateAuthorities( const SwTOXInternational& rIntl,
+             SwRootFrame const* pLayout );
 
     // insert sorted into array for creation
     void InsertSorted(std::unique_ptr<SwTOXSortTabBase> pBase);
@@ -73,6 +80,7 @@ public:
     // <_bNewTOX> : distinguish between the creation of a new table-of-content
     //              (true) or an update of a table-of-content (false)
     void Update( const SfxItemSet* pAttr = nullptr,
+                 SwRootFrame const* pLayout = nullptr,
                  const bool        _bNewTOX = false );
     void UpdatePageNum();               // insert page numbering
 
diff --git a/sw/source/core/inc/txmsrt.hxx b/sw/source/core/inc/txmsrt.hxx
index 548852698309..887d987da85c 100644
--- a/sw/source/core/inc/txmsrt.hxx
+++ b/sw/source/core/inc/txmsrt.hxx
@@ -30,6 +30,7 @@ class SwTextNode;
 class SwTextTOXMark;
 class SwIndex;
 class SwFormatField;
+class SwRootFrame;
 class IndexEntrySupplierWrapper;
 
 enum TOXSortType
@@ -141,32 +142,40 @@ struct SwTOXSortTabBase
     sal_uInt16  GetType() const         { return nType; }
     static SwTOIOptions  GetOptions()   { return nOpt; }
 
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const;
     virtual sal_uInt16  GetLevel()  const = 0;
     virtual bool    equivalent( const SwTOXSortTabBase& );
     virtual bool    sort_lt( const SwTOXSortTabBase& );
 
     virtual OUString  GetURL() const;
 
+    virtual bool IsFullPara() const;
+
+    // must be called
+    inline void InitText(SwRootFrame const*const pLayout);
     inline TextAndReading const & GetText() const;
     inline const css::lang::Locale& GetLocale() const;
 
 private:
-    mutable bool bValidText;
-    mutable TextAndReading m_aSort;
+    bool m_bValidText;
+    TextAndReading m_aSort;
 
-    virtual TextAndReading GetText_Impl() const = 0;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const = 0;
 };
 
-inline TextAndReading const & SwTOXSortTabBase::GetText() const
+inline void SwTOXSortTabBase::InitText(SwRootFrame const*const pLayout)
 {
-    if( !bValidText )
-    {
         // 'this' is 'SwTOXSortTabBase const*', so the virtual
         // mechanism will call the derived class' GetText_Impl
-        m_aSort = GetText_Impl();
-        bValidText = true;
-    }
+    assert(!m_bValidText);
+    m_aSort = GetText_Impl(pLayout);
+    m_bValidText = true;
+}
+
+inline TextAndReading const & SwTOXSortTabBase::GetText() const
+{
+    assert(m_bValidText);
     return m_aSort;
 }
 
@@ -184,13 +193,14 @@ struct SwTOXIndex : public SwTOXSortTabBase
                 const SwTOXInternational& rIntl,
                 const css::lang::Locale& rLocale );
 
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const override;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
     virtual sal_uInt16  GetLevel() const override;
     virtual bool    equivalent( const SwTOXSortTabBase& ) override;
     virtual bool    sort_lt( const SwTOXSortTabBase& ) override;
 
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
     sal_uInt8 const   nKeyLevel;
 };
@@ -206,7 +216,7 @@ struct SwTOXCustom : public SwTOXSortTabBase
     virtual bool   sort_lt( const SwTOXSortTabBase& ) override;
 
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
     TextAndReading const m_aKey;
     sal_uInt16 const  nLev;
@@ -220,10 +230,11 @@ struct SwTOXContent : public SwTOXSortTabBase
     SwTOXContent( const SwTextNode&, const SwTextTOXMark*,
                 const SwTOXInternational& rIntl );
 
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const override;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
     virtual sal_uInt16  GetLevel() const override;
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
 };
 
@@ -234,12 +245,14 @@ struct SwTOXPara : public SwTOXSortTabBase
     void    SetStartIndex(sal_Int32 nSet)    { nStartIndex = nSet; }
     void    SetEndIndex(sal_Int32 nSet)      { nEndIndex = nSet; }
 
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const override;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
     virtual sal_uInt16  GetLevel() const override;
 
     virtual OUString  GetURL() const override;
+    virtual bool IsFullPara() const override;
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
     SwTOXElement const eType;
     sal_uInt16 const m_nLevel;
@@ -258,7 +271,7 @@ struct SwTOXTable : public SwTOXSortTabBase
 
     virtual OUString  GetURL() const override;
 private:
-    virtual TextAndReading GetText_Impl() const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
     sal_uInt16 nLevel;
 };
@@ -267,8 +280,9 @@ struct SwTOXAuthority : public SwTOXSortTabBase
 {
 private:
     SwFormatField& m_rField;
-    virtual void    FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 nAuthField ) const override;
-    virtual TextAndReading GetText_Impl() const override;
+    virtual void    FillText(SwTextNode& rNd, const SwIndex& rInsPos,
+            sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
+    virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
 
 public:
     SwTOXAuthority( const SwContentNode& rNd, SwFormatField& rField, const SwTOXInternational& rIntl );
diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx
index bc74af17e9e2..44bbb5ec316e 100644
--- a/sw/source/core/inc/txtfrm.hxx
+++ b/sw/source/core/inc/txtfrm.hxx
@@ -29,6 +29,7 @@ namespace com { namespace sun { namespace star { namespace linguistic2 { class X
 namespace sw { namespace mark { class IMark; } }
 class SwCharRange;
 class SwTextNode;
+class SwTextAttrEnd;
 class SwTextFormatter;
 class SwTextFormatInfo;
 class SwParaPortion;
@@ -137,6 +138,8 @@ OUString GetExpandTextMerged(SwRootFrame const* pLayout,
         bool bWithSpacesForLevel, ExpandMode i_mode);
 
 bool IsMarkHidden(SwRootFrame const& rLayout, ::sw::mark::IMark const& rMark);
+bool IsMarkHintHidden(SwRootFrame const& rLayout,
+        SwTextNode const& rNode, SwTextAttrEnd const& rHint);
 
 } // namespace sw
 
diff --git a/sw/source/core/tox/ToxTextGenerator.cxx b/sw/source/core/tox/ToxTextGenerator.cxx
index 31dab3d5b2fe..7c29f0e7c979 100644
--- a/sw/source/core/tox/ToxTextGenerator.cxx
+++ b/sw/source/core/tox/ToxTextGenerator.cxx
@@ -21,6 +21,9 @@
 
 #include <chpfld.hxx>
 #include <cntfrm.hxx>
+#include <txtfrm.hxx>
+#include <rootfrm.hxx>
+#include <ndindex.hxx>
 #include <fchrfmt.hxx>
 #include <doc.hxx>
 #include <IDocumentLayoutAccess.hxx>
@@ -63,7 +66,9 @@ bool sortTabHasNoToxSourcesOrFirstToxSourceHasNoNode(const SwTOXSortTabBase& sor
 namespace sw {
 
 OUString
-ToxTextGenerator::GetNumStringOfFirstNode( const SwTOXSortTabBase& rBase, bool bUsePrefix, sal_uInt8 nLevel )
+ToxTextGenerator::GetNumStringOfFirstNode(const SwTOXSortTabBase& rBase,
+        bool bUsePrefix, sal_uInt8 nLevel,
+        SwRootFrame const*const pLayout)
 {
     if (sortTabHasNoToxSourcesOrFirstToxSourceHasNoNode(rBase)) {
         return OUString();
@@ -78,6 +83,10 @@ ToxTextGenerator::GetNumStringOfFirstNode( const SwTOXSortTabBase& rBase, bool b
     if (!pNd) {
         return sRet;
     }
+    if (pLayout && pLayout->IsHideRedlines())
+    {   // note: pNd could be any node, since it could be Sequence etc.
+        pNd = sw::GetParaPropsNode(*pLayout, SwNodeIndex(*pNd));
+    }
 
     const SwNumRule* pRule = pNd->GetNumRule();
     if (!pRule) {
@@ -85,7 +94,7 @@ ToxTextGenerator::GetNumStringOfFirstNode( const SwTOXSortTabBase& rBase, bool b
     }
 
     if (pNd->GetActualListLevel() < MAXLEVEL) {
-        sRet = pNd->GetNumString(bUsePrefix, nLevel);
+        sRet = pNd->GetNumString(bUsePrefix, nLevel, pLayout);
     }
 
     if (!sRet.isEmpty()) {
@@ -107,8 +116,8 @@ ToxTextGenerator::~ToxTextGenerator()
 {}
 
 OUString
-ToxTextGenerator::HandleChapterToken(const SwTOXSortTabBase& rBase, const SwFormToken& aToken,
-        SwDoc* pDoc) const
+ToxTextGenerator::HandleChapterToken(const SwTOXSortTabBase& rBase,
+        const SwFormToken& aToken, SwRootFrame const*const pLayout) const
 {
     if (sortTabHasNoToxSourcesOrFirstToxSourceHasNoNode(rBase)) {
         return OUString();
@@ -121,17 +130,18 @@ ToxTextGenerator::HandleChapterToken(const SwTOXSortTabBase& rBase, const SwForm
     }
 
     // #i53420#
-    const SwContentFrame* contentFrame = contentNode->getLayoutFrame(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
+    const SwContentFrame* contentFrame = contentNode->getLayoutFrame(pLayout);
     if (!contentFrame) {
         return OUString();
     }
 
-    return GenerateTextForChapterToken(aToken, contentFrame, contentNode);
+    return GenerateTextForChapterToken(aToken, contentFrame, contentNode, pLayout);
 }
 
 OUString
 ToxTextGenerator::GenerateTextForChapterToken(const SwFormToken& chapterToken, const SwContentFrame* contentFrame,
-        const SwContentNode *contentNode) const
+        const SwContentNode *contentNode,
+        SwRootFrame const*const pLayout) const
 {
     OUString retval;
 
@@ -142,14 +152,14 @@ ToxTextGenerator::GenerateTextForChapterToken(const SwFormToken& chapterToken, c
     // continue to support CF_NUMBER and CF_NUM_TITLE in order to handle ODF 1.0/1.1 written by OOo 3.x
     // in the same way as OOo 2.x would handle them.
     if (CF_NUM_NOPREPST_TITLE == chapterToken.nChapterFormat || CF_NUMBER == chapterToken.nChapterFormat) {
-        retval += aField.GetNumber(); // get the string number without pre/postfix
+        retval += aField.GetNumber(pLayout); // get the string number without pre/postfix
     }
     else if (CF_NUMBER_NOPREPST == chapterToken.nChapterFormat || CF_NUM_TITLE == chapterToken.nChapterFormat) {
-        retval += aField.GetNumber();
+        retval += aField.GetNumber(pLayout);
         retval += " ";
-        retval += aField.GetTitle();
+        retval += aField.GetTitle(pLayout);
     } else if (CF_TITLE == chapterToken.nChapterFormat) {
-        retval += aField.GetTitle();
+        retval += aField.GetTitle(pLayout);
     }
     return retval;
 }
@@ -158,7 +168,8 @@ ToxTextGenerator::GenerateTextForChapterToken(const SwFormToken& chapterToken, c
 // which page description is used, no appropriate one is found.
 void
 ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<SwTOXSortTabBase>> &entries,
-        sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess)
+        sal_uInt16 indexOfEntryToProcess, sal_uInt16 numberOfEntriesToProcess,
+        SwRootFrame const*const pLayout)
 {
     // pTOXNd is only set at the first mark
     SwTextNode* pTOXNd = const_cast<SwTextNode*>(entries.at(indexOfEntryToProcess)->pTOXNd);
@@ -186,11 +197,13 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<Sw
             {
             case TOKEN_ENTRY_NO:
                 // for TOC numbering
-                rText += GetNumStringOfFirstNode( rBase, aToken.nChapterFormat == CF_NUMBER, static_cast<sal_uInt8>(aToken.nOutlineLevel - 1) ) ;
+                rText += GetNumStringOfFirstNode(rBase,
+                    aToken.nChapterFormat == CF_NUMBER,
+                    static_cast<sal_uInt8>(aToken.nOutlineLevel - 1), pLayout);
                 break;
 
             case TOKEN_ENTRY_TEXT: {
-                HandledTextToken htt = HandleTextToken(rBase, pDoc->GetAttrPool());
+                HandledTextToken htt = HandleTextToken(rBase, pDoc->GetAttrPool(), pLayout);
                 ApplyHandledTextToken(htt, *pTOXNd);
             }
                 break;
@@ -198,8 +211,8 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<Sw
             case TOKEN_ENTRY:
                 {
                     // for TOC numbering
-                    rText += GetNumStringOfFirstNode( rBase, true, MAXLEVEL );
-                    HandledTextToken htt = HandleTextToken(rBase, pDoc->GetAttrPool() );
+                    rText += GetNumStringOfFirstNode(rBase, true, MAXLEVEL, pLayout);
+                    HandledTextToken htt = HandleTextToken(rBase, pDoc->GetAttrPool(), pLayout);
                     ApplyHandledTextToken(htt, *pTOXNd);
                 }
                 break;
@@ -221,7 +234,7 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<Sw
                 break;
 
             case TOKEN_CHAPTER_INFO:
-                rText += HandleChapterToken(rBase, aToken, pDoc);
+                rText += HandleChapterToken(rBase, aToken, pLayout);
                 break;
 
             case TOKEN_LINK_START:
@@ -236,7 +249,7 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc, const std::vector<std::unique_ptr<Sw
                 {
                     ToxAuthorityField eField = static_cast<ToxAuthorityField>(aToken.nAuthorityField);
                     SwIndex aIdx( pTOXNd, rText.getLength() );
-                    rBase.FillText( *pTOXNd, aIdx, static_cast<sal_uInt16>(eField) );
+                    rBase.FillText( *pTOXNd, aIdx, static_cast<sal_uInt16>(eField), pLayout );
                 }
                 break;
             case TOKEN_END: break;
@@ -290,40 +303,98 @@ ToxTextGenerator::CollectAttributesForTox(const SwTextAttr& hint, SwAttrPool& po
     return retval;
 }
 
+void ToxTextGenerator::GetAttributesForNode(
+    ToxTextGenerator::HandledTextToken & rResult,
+    sal_Int32 & rOffset,
+    SwTextNode const& rNode,
+    ToxWhitespaceStripper const& rStripper,
+    SwAttrPool & rPool,
+    SwRootFrame const*const pLayout)
+{
+    // note: this *must* use the same flags as SwTextNode::GetExpandText()
+    // or indexes will be off!
+    ExpandMode eMode = ExpandMode::ExpandFields;
+    if (pLayout && pLayout->IsHideRedlines())
+    {
+        eMode |= ExpandMode::HideDeletions;
+    }
+    ModelToViewHelper aConversionMap(rNode, pLayout, eMode);
+    if (SwpHints const*const pHints = rNode.GetpSwpHints())
+    {
+        for (size_t i = 0; i < pHints->Count(); ++i)
+        {
+            const SwTextAttr* pHint = pHints->Get(i);
+            std::shared_ptr<SfxItemSet> attributesToClone =
+                CollectAttributesForTox(*pHint, rPool);
+            if (attributesToClone->Count() <= 0) {
+                continue;
+            }
+
+            // sw_redlinehide: due to the ... interesting ... multi-level index
+            // mapping going on here, can't use the usual merged attr iterators :(
+
+            sal_Int32 const nStart(aConversionMap.ConvertToViewPosition(pHint->GetStart()));
+            sal_Int32 const nEnd(aConversionMap.ConvertToViewPosition(*pHint->GetAnyEnd()));
+            if (nStart != nEnd) // might be in delete redline, and useless anyway
+            {
+                std::unique_ptr<SwFormatAutoFormat> pClone(
+                    static_cast<SwFormatAutoFormat*>(pHint->GetAutoFormat().Clone()));
+                pClone->SetStyleHandle(attributesToClone);
+                rResult.autoFormats.push_back(std::move(pClone));
+                // note the rStripper is on the whole merged text, so need rOffset
+                rResult.startPositions.push_back(
+                    rStripper.GetPositionInStrippedString(rOffset + nStart));
+                rResult.endPositions.push_back(
+                    rStripper.GetPositionInStrippedString(rOffset + nEnd));
+            }
+        }
+    }
+    rOffset += aConversionMap.getViewText().getLength();
+}
+
 ToxTextGenerator::HandledTextToken
-ToxTextGenerator::HandleTextToken(const SwTOXSortTabBase& source, SwAttrPool& pool)
+ToxTextGenerator::HandleTextToken(const SwTOXSortTabBase& source,
+        SwAttrPool& pool, SwRootFrame const*const pLayout)
 {
     HandledTextToken result;
     ToxWhitespaceStripper stripper(source.GetText().sText);
     result.text = stripper.GetStrippedString();
 
-    if( source.aTOXSources.empty() )
+    // FIXME: there is a pre-existing problem that the index mapping of the
+    // attributes only works if the paragraph is fully selected
+    if (!source.IsFullPara() || source.aTOXSources.empty())
         return result;
 
     const SwTextNode* pSrc = source.aTOXSources.front().pNd->GetTextNode();
-    if (!pSrc || !pSrc->HasHints()) {
+    if (!pSrc)
+    {
         return result;
     }
-    const SwpHints& hints = pSrc->GetSwpHints();
-    for (size_t i = 0; i < hints.Count(); ++i) {
-        const SwTextAttr* hint = hints.Get(i);
-        std::shared_ptr<SfxItemSet> attributesToClone = CollectAttributesForTox(*hint, pool);
-        if (attributesToClone->Count() <= 0) {
-            continue;
+
+    sal_Int32 nOffset(0);
+    GetAttributesForNode(result, nOffset, *pSrc, stripper, pool, pLayout);
+    if (pLayout && pLayout->IsHideRedlines())
+    {
+        if (SwTextFrame const*const pFrame = static_cast<SwTextFrame*>(pSrc->getLayoutFrame(pLayout)))
+        {
+            if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara())
+            {
+                // pSrc already copied above
+                assert(pSrc == pMerged->pParaPropsNode);
+                for (sal_uLong i = pSrc->GetIndex() + 1;
+                     i <= pMerged->pLastNode->GetIndex(); ++i)
+                {
+                    SwNode *const pTmp(pSrc->GetNodes()[i]);
+                    if (pTmp->GetRedlineMergeFlag() == SwNode::Merge::NonFirst)
+                    {
+                        GetAttributesForNode(result, nOffset,
+                                *pTmp->GetTextNode(), stripper, pool, pLayout);
+                    }
+                }
+            }
         }
-        std::unique_ptr<SwFormatAutoFormat> clone(static_cast<SwFormatAutoFormat*>(hint->GetAutoFormat().Clone()));
-        clone->SetStyleHandle(attributesToClone);
-
-        result.autoFormats.push_back(std::move(clone));
-
-        ModelToViewHelper aConversionMap(*pSrc, nullptr, ExpandMode::ExpandFields);
-        result.startPositions.push_back(
-                stripper.GetPositionInStrippedString(aConversionMap.ConvertToViewPosition(
-                        hint->GetStart() )));
-        result.endPositions.push_back(
-                stripper.GetPositionInStrippedString(aConversionMap.ConvertToViewPosition(
-                        *hint->GetAnyEnd() )));
     }
+
     return result;
 }
 
diff --git a/sw/source/core/tox/tox.cxx b/sw/source/core/tox/tox.cxx
index 5219bbb3f551..6a5cebb92bf0 100644
--- a/sw/source/core/tox/tox.cxx
+++ b/sw/source/core/tox/tox.cxx
@@ -166,7 +166,7 @@ void SwTOXMark::InvalidateTOXMark()
     NotifyClients(&aMsgHint, &aMsgHint);
 }
 
-OUString SwTOXMark::GetText() const
+OUString SwTOXMark::GetText(SwRootFrame const*const pLayout) const
 {
     if( !m_aAltText.isEmpty() )
         return m_aAltText;
@@ -178,7 +178,7 @@ OUString SwTOXMark::GetText() const
         if( pEndIdx )
         {
             const sal_Int32 nStt = m_pTextAttr->GetStart();
-            return m_pTextAttr->GetpTextNd()->GetExpandText(nullptr, nStt, *pEndIdx-nStt);
+            return m_pTextAttr->GetpTextNd()->GetExpandText(pLayout, nStt, *pEndIdx-nStt);
         }
     }
 
diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx
index f335f13460a3..61ec0aad10f0 100644
--- a/sw/source/core/tox/txmsrt.cxx
+++ b/sw/source/core/tox/txmsrt.cxx
@@ -26,6 +26,9 @@
 #include <IDocumentMarkAccess.hxx>
 #include <docary.hxx>
 #include <cntfrm.hxx>
+#include <txtfrm.hxx>
+#include <rootfrm.hxx>
+#include <modeltoviewhelper.hxx>
 #include <node.hxx>
 #include <frmatr.hxx>
 #include <pam.hxx>
@@ -132,7 +135,8 @@ SwTOXSortTabBase::SwTOXSortTabBase( TOXSortType nTyp, const SwContentNode* pNd,
                                     const SwTOXInternational* pInter,
                                     const lang::Locale* pLocale )
     : pTOXNd( nullptr ), pTextMark( pMark ), pTOXIntl( pInter ),
-    nPos( 0 ), nCntPos( 0 ), nType( static_cast<sal_uInt16>(nTyp) ), bValidText( false )
+    nPos( 0 ), nCntPos( 0 ), nType( static_cast<sal_uInt16>(nTyp) )
+    , m_bValidText( false )
 {
     if ( pLocale )
         aLocale = *pLocale;
@@ -185,8 +189,13 @@ OUString SwTOXSortTabBase::GetURL() const
     return OUString();
 }
 
+bool SwTOXSortTabBase::IsFullPara() const
+{
+    return false;
+}
+
 void SwTOXSortTabBase::FillText( SwTextNode& rNd, const SwIndex& rInsPos,
-                                    sal_uInt16 ) const
+                                    sal_uInt16, SwRootFrame const*const) const
 {
     rNd.InsertText( GetText().sText, rInsPos );
 }
@@ -328,7 +337,7 @@ bool SwTOXIndex::sort_lt(const SwTOXSortTabBase& rCmpBase)
 
 // The keyword itself
 
-TextAndReading SwTOXIndex::GetText_Impl() const
+TextAndReading SwTOXIndex::GetText_Impl(SwRootFrame const*const pLayout) const
 {
     OSL_ENSURE(pTextMark, "pTextMark == 0, No keyword");
     const SwTOXMark& rTOXMark = pTextMark->GetTOXMark();
@@ -350,7 +359,7 @@ TextAndReading SwTOXIndex::GetText_Impl() const
         break;
         case FORM_ENTRY          :
         {
-            aRet.sText = rTOXMark.GetText();
+            aRet.sText = rTOXMark.GetText(pLayout);
             aRet.sReading = rTOXMark.GetTextReading();
         }
         break;
@@ -364,8 +373,10 @@ TextAndReading SwTOXIndex::GetText_Impl() const
     return aRet;
 }
 
-void SwTOXIndex::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
+void SwTOXIndex::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
+        SwRootFrame const*const pLayout) const
 {
+    assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
     const sal_Int32* pEnd = pTextMark->End();
 
     TextAndReading aRet;
@@ -373,9 +384,13 @@ void SwTOXIndex::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 )
             !(GetOptions() & SwTOIOptions::KeyAsEntry))
     {
         aRet.sText = static_cast<const SwTextNode*>(aTOXSources[0].pNd)->GetExpandText(
-                            nullptr,
+                            pLayout,
                             pTextMark->GetStart(),
-                            *pEnd - pTextMark->GetStart());
+                            *pEnd - pTextMark->GetStart(),
+                            false, false, false,
+                            pLayout && pLayout->IsHideRedlines()
+                                ? ExpandMode::HideDeletions
+                                : ExpandMode(0));
         if(SwTOIOptions::InitialCaps & nOpt && pTOXIntl && !aRet.sText.isEmpty())
         {
             aRet.sText = pTOXIntl->ToUpper( aRet.sText, 0 ) + aRet.sText.copy(1);
@@ -432,7 +447,7 @@ sal_uInt16 SwTOXCustom::GetLevel() const
     return nLev;
 }
 
-TextAndReading SwTOXCustom::GetText_Impl() const
+TextAndReading SwTOXCustom::GetText_Impl(SwRootFrame const*const) const
 {
     return m_aKey;
 }
@@ -446,29 +461,36 @@ SwTOXContent::SwTOXContent( const SwTextNode& rNd, const SwTextTOXMark* pMark,
 
 // The content's text
 
-TextAndReading SwTOXContent::GetText_Impl() const
+TextAndReading SwTOXContent::GetText_Impl(SwRootFrame const*const pLayout) const
 {
     const sal_Int32* pEnd = pTextMark->End();
     if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() )
     {
         return TextAndReading(
             static_cast<const SwTextNode*>(aTOXSources[0].pNd)->GetExpandText(
-                                     nullptr,
+                                     pLayout,
                                      pTextMark->GetStart(),
-                                     *pEnd - pTextMark->GetStart() ),
+                                     *pEnd - pTextMark->GetStart(),
+                            false, false, false,
+                            pLayout && pLayout->IsHideRedlines()
+                                ? ExpandMode::HideDeletions
+                                : ExpandMode(0)),
             pTextMark->GetTOXMark().GetTextReading());
     }
 
     return TextAndReading(pTextMark->GetTOXMark().GetAlternativeText(), OUString());
 }
 
-void SwTOXContent::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
+void SwTOXContent::FillText(SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
+        SwRootFrame const*const pLayout) const
 {
+    assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
     const sal_Int32* pEnd = pTextMark->End();
     if( pEnd && !pTextMark->GetTOXMark().IsAlternativeText() )
+        // sw_redlinehide: this probably won't HideDeletions
         static_cast<const SwTextNode*>(aTOXSources[0].pNd)->CopyExpandText(
                 rNd, &rInsPos, pTextMark->GetStart(),
-                *pEnd - pTextMark->GetStart(), nullptr );
+                *pEnd - pTextMark->GetStart(), pLayout);
     else
     {
         rNd.InsertText( GetText().sText, rInsPos );
@@ -495,20 +517,34 @@ SwTOXPara::SwTOXPara( const SwContentNode& rNd, SwTOXElement eT, sal_uInt16 nLev
 {
 }
 
-TextAndReading SwTOXPara::GetText_Impl() const
+TextAndReading SwTOXPara::GetText_Impl(SwRootFrame const*const pLayout) const
 {
     const SwContentNode* pNd = aTOXSources[0].pNd;
     switch( eType )
     {
     case SwTOXElement::Sequence:
+        if (nStartIndex != 0 || nEndIndex != -1)
+        {
+            // sw_redlinehide: "captions" are a rather fuzzily defined concept anyway
+            return TextAndReading(static_cast<const SwTextNode*>(pNd)->GetExpandText(
+                        pLayout,
+                        nStartIndex,
+                        nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
+                        false, false, false,
+                        pLayout && pLayout->IsHideRedlines()
+                            ? ExpandMode::HideDeletions
+                            : ExpandMode(0)),
+                    OUString());
+        }
+        BOOST_FALLTHROUGH;
     case SwTOXElement::Template:
     case SwTOXElement::OutlineLevel:
         {
-            return TextAndReading(static_cast<const SwTextNode*>(pNd)->GetExpandText(
-                    nullptr,
-                    nStartIndex,
-                    nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
-                    false, false, false),
+            assert(nStartIndex == 0);
+            assert(nEndIndex == -1);
+            return TextAndReading(sw::GetExpandTextMerged(
+                        pLayout, *static_cast<const SwTextNode*>(pNd),
+                        false, false, ExpandMode(0)),
                     OUString());
         }
         break;
@@ -536,14 +572,51 @@ TextAndReading SwTOXPara::GetText_Impl() const
     return TextAndReading();
 }
 
-void SwTOXPara::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16 ) const
+void SwTOXPara::FillText( SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt16,
+        SwRootFrame const*const pLayout) const
 {
+    assert(!"sw_redlinehide: this is dead code, Bibliography only has SwTOXAuthority");
     if( SwTOXElement::Template == eType || SwTOXElement::Sequence == eType  || SwTOXElement::OutlineLevel == eType)
     {
         const SwTextNode* pSrc = static_cast<const SwTextNode*>(aTOXSources[0].pNd);
-        pSrc->CopyExpandText( rNd, &rInsPos, nStartIndex,
-                nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
-                nullptr, false, false, true );
+        if (SwTOXElement::Sequence == eType
+            && (nStartIndex != 0 || nEndIndex != -1))
+        {
+            pSrc->CopyExpandText( rNd, &rInsPos, nStartIndex,
+                    nEndIndex == -1 ? -1 : nEndIndex - nStartIndex,
+                    pLayout, false, false, true );
+        }
+        else
+        {
+            assert(nStartIndex == 0);
+            assert(nEndIndex == -1);
+            // sw_redlinehide: this probably won't HideDeletions
+            pSrc->CopyExpandText( rNd, &rInsPos, 0, -1,
+                    pLayout, false, false, true );
+            if (pLayout && pLayout->IsHideRedlines())
+            {
+                if (SwTextFrame const*const pFrame = static_cast<SwTextFrame*>(pSrc->getLayoutFrame(pLayout)))
+                {
+                    if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara())
+                    {
+                        // pSrc already copied above
+                        assert(pSrc == pMerged->pParaPropsNode);
+                        for (sal_uLong i = pSrc->GetIndex() + 1;
+                             i <= pMerged->pLastNode->GetIndex(); ++i)
+                        {
+                            SwNode *const pTmp(pSrc->GetNodes()[i]);
+                            if (pTmp->GetRedlineMergeFlag() == SwNode::Merge::NonFirst)
+                            {
+
+                                pTmp->GetTextNode()->CopyExpandText(
+                                        rNd, &rInsPos, 0, -1,
+                                        pLayout, false, false, false );
+                            }
+                        }
+                    }
+                }
+            }
+        }
     }
     else
     {
@@ -617,6 +690,19 @@ OUString SwTOXPara::GetURL() const
     return aText;
 }
 
+bool SwTOXPara::IsFullPara() const
+{
+    switch (eType)
+    {
+        case SwTOXElement::Sequence:
+        case SwTOXElement::Template:
+        case SwTOXElement::OutlineLevel:
+            return nStartIndex == 0 && nEndIndex == -1;
+        default:
+            return false;
+    }
+}
+
 // Table
 SwTOXTable::SwTOXTable( const SwContentNode& rNd )
     : SwTOXSortTabBase( TOX_SORT_TABLE, &rNd, nullptr, nullptr ),
@@ -624,7 +710,7 @@ SwTOXTable::SwTOXTable( const SwContentNode& rNd )
 {
 }
 
-TextAndReading SwTOXTable::GetText_Impl() const
+TextAndReading SwTOXTable::GetText_Impl(SwRootFrame const*const) const
 {
     const SwNode* pNd = aTOXSources[0].pNd;
     if( pNd )
@@ -688,24 +774,25 @@ sal_uInt16 SwTOXAuthority::GetLevel() const
     return nRet;
 }
 
-static OUString lcl_GetText(SwFormatField const& rField)
+static OUString lcl_GetText(SwFormatField const& rField, SwRootFrame const*const pLayout)
 {
-    return rField.GetField()->ExpandField(true, nullptr);
+    return rField.GetField()->ExpandField(true, pLayout);
 }
 
-TextAndReading SwTOXAuthority::GetText_Impl() const
+TextAndReading SwTOXAuthority::GetText_Impl(SwRootFrame const*const pLayout) const
 {
-    return TextAndReading(lcl_GetText(m_rField), OUString());
+    return TextAndReading(lcl_GetText(m_rField, pLayout), OUString());
 }
 
 void    SwTOXAuthority::FillText( SwTextNode& rNd,
-                        const SwIndex& rInsPos, sal_uInt16 nAuthField ) const
+                        const SwIndex& rInsPos, sal_uInt16 nAuthField,
+        SwRootFrame const*const pLayout) const
 {
     SwAuthorityField* pField = static_cast<SwAuthorityField*>(m_rField.GetField());
     OUString sText;
     if(AUTH_FIELD_IDENTIFIER == nAuthField)
     {
-        sText = lcl_GetText(m_rField);
+        sText = lcl_GetText(m_rField, pLayout);
         const SwAuthorityFieldType* pType = static_cast<const SwAuthorityFieldType*>(pField->GetTyp());
         sal_Unicode cChar = pType->GetPrefix();
         if(cChar && cChar != ' ')
diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx
index 21887c273740..7e40304a6f2a 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -1272,7 +1272,7 @@ void SAL_CALL SwXDocumentIndex::refresh()
                     "SwXDocumentIndex::refresh: must be in attached state",
                      static_cast< ::cppu::OWeakObject*>(this));
         }
-        pTOXBase->Update();
+        pTOXBase->Update(nullptr, m_pImpl->m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
 
         // the insertion of TOC will affect the document layout
         lcl_CalcLayout(m_pImpl->m_pDoc);
@@ -1354,7 +1354,8 @@ SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange)
     }
     //TODO: apply Section attributes (columns and background)
     SwTOXBaseSection *const pTOX =
-        pDoc->InsertTableOf( *aPam.GetPoint(), rTOXBase );
+        pDoc->InsertTableOf( *aPam.GetPoint(), rTOXBase, nullptr, false,
+                m_pImpl->m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
 
     pDoc->SetTOXBaseName(*pTOX, m_pImpl->m_pProps->GetTOXBase().GetTOXName());
 
diff --git a/sw/source/ui/index/multmrk.cxx b/sw/source/ui/index/multmrk.cxx
index 735927a58ff5..7cc876e1f004 100644
--- a/sw/source/ui/index/multmrk.cxx
+++ b/sw/source/ui/index/multmrk.cxx
@@ -20,6 +20,7 @@
 #include <swtypes.hxx>
 #include <multmrk.hxx>
 #include <toxmgr.hxx>
+#include <wrtsh.hxx>
 
 SwMultiTOXMarkDlg::SwMultiTOXMarkDlg(weld::Window* pParent, SwTOXMgr& rTOXMgr)
     : GenericDialogController(pParent, "modules/swriter/ui/selectindexdialog.ui", "SelectIndexDialog")
@@ -35,7 +36,7 @@ SwMultiTOXMarkDlg::SwMultiTOXMarkDlg(weld::Window* pParent, SwTOXMgr& rTOXMgr)
 
     sal_uInt16 nSize = m_rMgr.GetTOXMarkCount();
     for(sal_uInt16 i=0; i < nSize; ++i)
-        m_xTOXLB->append_text(m_rMgr.GetTOXMark(i)->GetText());
+        m_xTOXLB->append_text(m_rMgr.GetTOXMark(i)->GetText(m_rMgr.GetShell()->GetLayout()));
 
     m_xTOXLB->select(0);
     m_xTextFT->set_label(m_rMgr.GetTOXMark(0)->GetTOXType()->GetTypeName());
diff --git a/sw/source/ui/index/swuiidxmrk.cxx b/sw/source/ui/index/swuiidxmrk.cxx
index db0a9f85e6d7..b30f5769710d 100644
--- a/sw/source/ui/index/swuiidxmrk.cxx
+++ b/sw/source/ui/index/swuiidxmrk.cxx
@@ -397,13 +397,14 @@ void SwIndexMarkPane::InsertUpdate()
         InsertMark();
 
         if ( m_pTOXMgr->GetCurTOXMark())
-            aRewriter.AddRule(UndoArg1, m_pTOXMgr->GetCurTOXMark()->GetText());
+            aRewriter.AddRule(UndoArg1,
+                    m_pTOXMgr->GetCurTOXMark()->GetText(m_pSh->GetLayout()));
     }
     else if( !m_pSh->HasReadonlySel() )
     {
         if ( m_pTOXMgr->GetCurTOXMark())
             aRewriter.AddRule(UndoArg1,
-                              m_pTOXMgr->GetCurTOXMark()->GetText());
+                    m_pTOXMgr->GetCurTOXMark()->GetText(m_pSh->GetLayout()));
 
         if( m_bDel )
             m_pTOXMgr->DeleteTOXMark();
@@ -761,7 +762,7 @@ void SwIndexMarkPane::UpdateDialog()
 
     SwViewShell::SetCareDialog(m_xDialog);
 
-    m_aOrgStr = pMark->GetText();
+    m_aOrgStr = pMark->GetText(m_pSh->GetLayout());
     m_xEntryED->set_text(m_aOrgStr);
 
     // set index type
@@ -779,7 +780,7 @@ void SwIndexMarkPane::UpdateDialog()
         bKeyEnable = true;
         bKey1HasText = bKey2Enable = !pMark->GetPrimaryKey().isEmpty();
         bKey2HasText = !pMark->GetSecondaryKey().isEmpty();
-        bEntryHasText = !pMark->GetText().isEmpty();
+        bEntryHasText = !pMark->GetText(m_pSh->GetLayout()).isEmpty();
         m_xKey1DCB->set_entry_text( pMark->GetPrimaryKey() );
         m_xKey2DCB->set_entry_text( pMark->GetSecondaryKey() );
         m_xPhoneticED0->set_text( pMark->GetTextReading() );
diff --git a/sw/source/uibase/inc/toxmgr.hxx b/sw/source/uibase/inc/toxmgr.hxx
index 6f0ccc290721..12cad3c88fe8 100644
--- a/sw/source/uibase/inc/toxmgr.hxx
+++ b/sw/source/uibase/inc/toxmgr.hxx
@@ -256,6 +256,7 @@ public:
     bool    UpdateOrInsertTOX(const SwTOXDescription& rDesc, SwTOXBase** ppBase, const SfxItemSet* pSet);
 
     const SwTOXType*    GetTOXType(TOXTypes eTyp) const;
+    SwWrtShell * GetShell() { return pSh; }
 };
 
 // inlines
diff --git a/sw/source/uibase/index/toxmgr.cxx b/sw/source/uibase/index/toxmgr.cxx
index d77a9f8d5bd3..afae269713fb 100644
--- a/sw/source/uibase/index/toxmgr.cxx
+++ b/sw/source/uibase/index/toxmgr.cxx
@@ -440,7 +440,7 @@ bool SwTOXMgr::UpdateOrInsertTOX(const SwTOXDescription& rDesc,
             pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::TOXCHANGE, nullptr);
         }
 
-        pDoc->ChgTOX(*pTOX, *pNewTOX);
+        pDoc->ChangeTOX(*pTOX, *pNewTOX, *pSh->GetLayout());
 
         pTOX->DisableKeepExpression();
         pSh->UpdateTableOf(*pTOX, pSet);


More information about the Libreoffice-commits mailing list