sw/source/core/docnode/nodes.cxx |   55 +++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 24 deletions(-)

New commits:
commit faf2d9e2cb13c3750ac359338f8f31fc1afce368
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Jul 17 17:32:07 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Jul 17 19:33:41 2023 +0200

    sw: handle sequence of sections containing only table
    
    SwNodes::FindPrvNxtFrameNode() still relies on the special-case code at
    the end to handle this situation, which exists only in the forward
    direction, and since commit af4e20426ad24c6f2c0164b37472f2b7b54ecd30
    there's an assert which is triggered by forum-de3-11230.odt
    
    Add the handling to the loop, both backwards and forwards.
    
    Change-Id: I79702653ec6fc27854f664c2a41c02f9c97edff0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154553
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index 06a50c4de33b..45a02bf5d5a0 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -2242,6 +2242,22 @@ SwNode* SwNodes::FindPrvNxtFrameNode( const SwNode& 
rFrameNd,
         else
         {
             pFrameNd = GoPrevSection( &aIdx, true, false );
+            // did we move *into* a table?
+            if (pFrameNd)
+            {
+                for (SwTableNode * pTable = pFrameNd->FindTableNode();
+                    pTable && pTable->EndOfSectionIndex() < 
rFrameNd.GetIndex();
+                    pTable = pTable->StartOfSectionNode()->FindTableNode())
+                {
+                    pFrameNd = pTable->EndOfSectionNode();
+                }
+                if (pFrameNd->IsEndNode())
+                {   // GoPrevSection() checks that text node isn't 
section-hidden,
+                    // so table node between can't be section-hidden either
+                    assert(pFrameNd->StartOfSectionNode()->IsTableNode());
+                    continue; // check other hidden conditions on next 
iteration
+                }
+            }
             if ( nullptr != pFrameNd && !(
                     ::CheckNodesRange( aIdx.GetNode(), rFrameNd, true ) &&
                     // Never out of the table at the start
@@ -2299,6 +2315,21 @@ SwNode* SwNodes::FindPrvNxtFrameNode( const SwNode& 
rFrameNd,
         else
         {
             pFrameNd = GoNextSection( &aIdx, true, false );
+            // did we move *into* a table?
+            if (pFrameNd)
+            {
+                for (SwTableNode * pTable = pFrameNd->FindTableNode();
+                    pTable && pEnd->GetIndex() < pTable->GetIndex();
+                    pTable = pTable->StartOfSectionNode()->FindTableNode())
+                {
+                    pFrameNd = pTable;
+                }
+                if (pFrameNd->IsTableNode())
+                {   // GoNextSection() checks that text node isn't 
section-hidden,
+                    // so table node between can't be section-hidden either
+                    continue; // check other hidden conditions on next 
iteration
+                }
+            }
             // NEVER leave the section when doing this!
             if (pFrameNd
                 && !(::CheckNodesRange(aIdx.GetNode(), rFrameNd, true)
@@ -2316,30 +2347,6 @@ SwNode* SwNodes::FindPrvNxtFrameNode( const SwNode& 
rFrameNd,
     }
     while (pFrameNd != nullptr);
 
-    // probably this is dead code, because the GoNextSection()
-    // should have ended up in the first text node in the table and
-    // then checked it's in a table?
-    {
-        aIdx = pEnd->GetIndex() + 1;
-
-        pFrameNd = nullptr;
-
-        // is there some sectionnodes before a tablenode?
-        while( aIdx.GetNode().IsSectionNode() )
-        {
-            const SwSection& rSect = aIdx.GetNode().
-                GetSectionNode()->GetSection();
-            if( rSect.IsHiddenFlag() )
-                aIdx = aIdx.GetNode().EndOfSectionIndex()+1;
-            else
-                ++aIdx;
-        }
-        if( aIdx.GetNode().IsTableNode() )
-        {
-            pFrameNd = &aIdx.GetNode();
-            assert(!"this isn't dead code?");
-        }
-    }
     return pFrameNd;
 }
 

Reply via email to