summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2021-12-21 13:47:32 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2021-12-23 11:12:39 +0100
commit04313336e665c10bbb2d1a47e41e7b38e5c3c2cb (patch)
tree1cd4c4731fa0637534eeaab5fc7db9b737c5ce88
parenttdf#144672 fix Index entries in Naviator are always grayed out (diff)
downloadcore-04313336e665c10bbb2d1a47e41e7b38e5c3c2cb.tar.gz
core-04313336e665c10bbb2d1a47e41e7b38e5c3c2cb.zip
sw: simplify SwNodes::FindPrvNxtFrameNode(), improve comments
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127269 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit 25aa814aa466cb0a59e34dfef33c50065c445f60) sw: simplify SwNodes::FindPrvNxtFrameNode(), pEnd is always passed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127270 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit e0f13ce0f9e2dac836c42141bb848d2bf4fbda75) sw: simplify SwNodes::FindPrvNxtFrameNode(), de-golf conditionals Change-Id: Ie5b35793ce38e6338e34d47725e649a56078d603 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127271 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit b922988e2cd57c9397b9e512a7616a10612b2b8f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127315 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--sw/inc/ndarr.hxx4
-rw-r--r--sw/source/core/docnode/nodes.cxx93
2 files changed, 51 insertions, 46 deletions
diff --git a/sw/inc/ndarr.hxx b/sw/inc/ndarr.hxx
index 7e095c8fb0a6..6167708d0eb6 100644
--- a/sw/inc/ndarr.hxx
+++ b/sw/inc/ndarr.hxx
@@ -303,8 +303,8 @@ public:
const SwDoc& GetDoc() const { return m_rMyDoc; }
/** Search previous / next content node or table node with frames.
- If no end is given begin with the FrameIndex, else start search
- with that before rFrameIdx and pEnd at the back.
+ Search is started backward with the one before rFrameIdx and
+ forward after pEnd.
If no valid node is found, return 0. rFrameIdx points to the node with frames. **/
SwNode* FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
const SwNode* pEnd ) const;
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index e7af18a1c16a..6be389697304 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -2027,53 +2027,53 @@ SwContentNode* SwNodes::GoPrevSection( SwNodeIndex * pIdx,
return nullptr;
}
-//TODO: improve documentation
//TODO: The inventor of the "single responsibility principle" will be crying if you ever show this code to him!
-/** find the next/previous ContentNode or a table node with frames
+/** find the next/previous ContentNode or table node that should have layout
+ * frames that are siblings to the ones of the node at rFrameIdx.
*
- * If no pEnd is given, search is started with FrameIndex; otherwise
- * search is started with the one before rFrameIdx and after pEnd.
+ * Search is started backward with the one before rFrameIdx and
+ * forward after pEnd.
*
- * @param rFrameIdx node with frames to search in
- * @param pEnd ???
- * @return result node; 0 (!!!) if not found
+ * @param rFrameIdx in: node with frames to search in; out: found node
+ * @param pEnd last node after rFrameIdx that should be excluded from search
+ * @return result node; 0 if not found
*/
SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
const SwNode* pEnd ) const
{
+ assert(pEnd != nullptr); // every caller currently
+
SwNode* pFrameNd = nullptr;
// no layout -> skip
if( GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell() )
{
- SwNode* pSttNd = &rFrameIdx.GetNode();
+ SwNode *const pSttNd = &rFrameIdx.GetNode();
- // move of a hidden section?
- SwSectionNode* pSectNd = pSttNd->IsSectionNode()
+ // inside a hidden section?
+ SwSectionNode *const pSectNd = pSttNd->IsSectionNode()
? pSttNd->StartOfSectionNode()->FindSectionNode()
: pSttNd->FindSectionNode();
if( !( pSectNd && pSectNd->GetSection().CalcHiddenFlag() ) )
{
// in a table in table situation we have to assure that we don't leave the
// outer table cell when the inner table is looking for a PrvNxt...
- SwTableNode* pTableNd = pSttNd->IsTableNode()
+ SwTableNode *const pTableNd = pSttNd->IsTableNode()
? pSttNd->StartOfSectionNode()->FindTableNode()
: pSttNd->FindTableNode();
SwNodeIndex aIdx( rFrameIdx );
- SwNode* pNd;
- if( pEnd )
- {
- --aIdx;
- pNd = &aIdx.GetNode();
- }
- else
- pNd = pSttNd;
+ --aIdx;
+ SwNode *const pNd = &aIdx.GetNode();
- if( ( pFrameNd = pNd )->IsContentNode() )
+ pFrameNd = pNd;
+ if (pFrameNd->IsContentNode())
+ {
rFrameIdx = aIdx;
-
+ return pFrameNd;
+ }
// search forward or backward for a content node
- else if( nullptr != ( pFrameNd = GoPrevSection( &aIdx, true, false )) &&
+ pFrameNd = GoPrevSection( &aIdx, true, false );
+ if ( nullptr != pFrameNd &&
::CheckNodesRange( aIdx, rFrameIdx, true ) &&
// Never out of the table at the start
pFrameNd->FindTableNode() == pTableNd &&
@@ -2088,29 +2088,34 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
}
else
{
- if( pEnd )
- aIdx = pEnd->GetIndex() + 1;
- else
- aIdx = rFrameIdx;
+ aIdx = pEnd->GetIndex() + 1;
- // NEVER leave the section when doing this!
- if( ( pEnd && ( pFrameNd = &aIdx.GetNode())->IsContentNode() ) ||
- ( nullptr != ( pFrameNd = GoNextSection( &aIdx, true, false )) &&
- ::CheckNodesRange( aIdx, rFrameIdx, true ) &&
- ( pFrameNd->FindTableNode() == pTableNd &&
- // NEVER go out of the table cell at the end
- (!pFrameNd->FindTableNode() || pFrameNd->FindTableBoxStartNode()
- == pSttNd->FindTableBoxStartNode() ) ) &&
- (!pSectNd || pSttNd->IsSectionNode() ||
- pSectNd->EndOfSectionIndex() > pFrameNd->GetIndex())
- ))
+ pFrameNd = &aIdx.GetNode();
+ if (!pFrameNd->IsContentNode())
+ {
+ pFrameNd = GoNextSection( &aIdx, true, false );
+ // NEVER leave the section when doing this!
+ if (pFrameNd
+ && !(::CheckNodesRange(aIdx, rFrameIdx, true)
+ && (pFrameNd->FindTableNode() == pTableNd &&
+ // NEVER go out of the table cell at the end
+ (!pFrameNd->FindTableNode() || pFrameNd->FindTableBoxStartNode()
+ == pSttNd->FindTableBoxStartNode()))
+ && (!pSectNd || pSttNd->IsSectionNode() ||
+ pSectNd->EndOfSectionIndex() > pFrameNd->GetIndex()))
+ )
+ {
+ pFrameNd = nullptr;
+ }
+ }
+ if (pFrameNd && pFrameNd->IsContentNode())
{
// Undo when merging a table with one before, if there is also one after it.
// However, if the node is in a table, it needs to be returned if the
// SttNode is a section or a table!
- SwTableNode* pTableNode;
+ SwTableNode *const pTableNode = pFrameNd->FindTableNode();
if (pSttNd->IsTableNode() &&
- nullptr != (pTableNode = pFrameNd->FindTableNode()) &&
+ nullptr != pTableNode &&
// TABLE IN TABLE:
pTableNode != pSttNd->StartOfSectionNode()->FindTableNode())
{
@@ -2127,13 +2132,13 @@ SwNode* SwNodes::FindPrvNxtFrameNode( SwNodeIndex& rFrameIdx,
}
else
{
- if( pEnd )
- aIdx = pEnd->GetIndex() + 1;
- else
- aIdx = rFrameIdx.GetIndex() + 1;
+ aIdx = pEnd->GetIndex() + 1;
- if( (pFrameNd = &aIdx.GetNode())->IsTableNode() )
+ pFrameNd = &aIdx.GetNode();
+ if (pFrameNd->IsTableNode())
+ {
rFrameIdx = aIdx;
+ }
else
{
pFrameNd = nullptr;