sw/source/core/docnode/nodes.cxx | 69 ++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 26 deletions(-)
New commits: commit c69f4a34c65572fbfe01298d90cb0aa6c7afb4de Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Wed Jul 19 15:54:07 2023 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue Jul 25 20:51:30 2023 +0200 tdf#153115 sw: fix yet another FindPrvNxtFrameNode() issue In the SwUndoTextToTable for the middle cell it happens that there is no frame remaining in the cell frame and SwNodes::FindPrvNxtFrameNode() erroneously returns a frame from inside the preceding cell, so it creates the frame in the wrong cell. (regression from commit faf2d9e2cb13c3750ac359338f8f31fc1afce368) Change-Id: I2e4f460541e20dda23c1fafb6d63c023dae9b152 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154654 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> (cherry picked from commit ba99cc9d9cf781d9b3888e1cf5becd95bb9fc6d2) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154622 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx index 45a02bf5d5a0..c045aa57023d 100644 --- a/sw/source/core/docnode/nodes.cxx +++ b/sw/source/core/docnode/nodes.cxx @@ -2239,7 +2239,8 @@ SwNode* SwNodes::FindPrvNxtFrameNode( const SwNode& rFrameNd, pFrameNd = &aIdx.GetNode(); } } - else + else if (pFrameNd->IsSectionNode() + || (pFrameNd->IsEndNode() && pFrameNd->StartOfSectionNode()->IsSectionNode())) { pFrameNd = GoPrevSection( &aIdx, true, false ); // did we move *into* a table? @@ -2272,6 +2273,10 @@ SwNode* SwNodes::FindPrvNxtFrameNode( const SwNode& rFrameNd, pFrameNd = nullptr; // no preceding content node, stop search } } + else + { + pFrameNd = nullptr; // no preceding content node, stop search + } } while (pFrameNd != nullptr); @@ -2312,7 +2317,8 @@ SwNode* SwNodes::FindPrvNxtFrameNode( const SwNode& rFrameNd, pFrameNd = &aIdx.GetNode(); } } - else + else if (pFrameNd->IsSectionNode() + || (pFrameNd->IsEndNode() && pFrameNd->StartOfSectionNode()->IsSectionNode())) { pFrameNd = GoNextSection( &aIdx, true, false ); // did we move *into* a table? @@ -2344,6 +2350,10 @@ SwNode* SwNodes::FindPrvNxtFrameNode( const SwNode& rFrameNd, pFrameNd = nullptr; // no following content node, stop search } } + else + { + pFrameNd = nullptr; // no preceding content node, stop search + } } while (pFrameNd != nullptr); commit f8b5a12e7034f74fa5ea099634a1202d94e15e1e Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Mon Jul 17 17:32:07 2023 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue Jul 25 20:51:19 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> (cherry picked from commit faf2d9e2cb13c3750ac359338f8f31fc1afce368) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154533 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> 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; }