sw/source/uibase/wrtsh/wrtsh1.cxx | 189 ++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 96 deletions(-)
New commits: commit eb88769b907a3e0e4c92f6310970d4e5fe32f75b Author: Jim Raykowski <[email protected]> AuthorDate: Sun Sep 28 17:16:00 2025 -0800 Commit: Jim Raykowski <[email protected]> CommitDate: Tue Sep 30 06:17:42 2025 +0200 Flatten lcl_FoldedOutlineNodeEndOfParaSplit Change-Id: I3b211078c3c29fd7e78d6a697ba433cb9c66c861 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191586 Tested-by: Jenkins Reviewed-by: Jim Raykowski <[email protected]> diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index d64636914d6c..ebe08ca85f29 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -1310,119 +1310,116 @@ void SwWrtShell::InsertFootnote(const OUString &rStr, bool bEndNote, bool bEdit } // tdf#141634 -static bool lcl_FoldedOutlineNodeEndOfParaSplit(SwWrtShell *pThis) +static bool lcl_FoldedOutlineNodeEndOfParaSplit(SwWrtShell* pThis) { SwTextNode* pTextNode = pThis->GetCursor()->GetPointNode().GetTextNode(); - if (pTextNode && pTextNode->IsOutline()) - { - if (!pTextNode->GetAttrOutlineContentVisible()) - { - const SwNodes& rNodes = pThis->GetNodes(); - const SwOutlineNodes& rOutlineNodes = rNodes.GetOutLineNds(); - SwOutlineNodes::size_type nPos; - (void) rOutlineNodes.Seek_Entry(pTextNode, &nPos); + const SwNodes& rNodes = pThis->GetNodes(); + const SwOutlineNodes& rOutlineNodes = rNodes.GetOutLineNds(); + SwOutlineNodes::size_type nPos; - SwNode* pSttNd = rOutlineNodes[nPos]; + if (!pTextNode || pTextNode->GetAttrOutlineContentVisible() + || !rOutlineNodes.Seek_Entry(pTextNode, &nPos)) + return false; - // determine end node of folded outline content - SwNode* pEndNd = &rNodes.GetEndOfContent(); - if (rOutlineNodes.size() > nPos + 1) - pEndNd = rOutlineNodes[nPos + 1]; + SwNode* pSttNd = rOutlineNodes[nPos]; - if (pThis->GetViewOptions()->IsTreatSubOutlineLevelsAsContent()) - { - // get the next outline node after the folded outline content (iPos) - // it is the next outline node with the same level or less - int nLevel = pSttNd->GetTextNode()->GetAttrOutlineLevel(); - SwOutlineNodes::size_type iPos = nPos; - while (++iPos < rOutlineNodes.size() && - rOutlineNodes[iPos]->GetTextNode()->GetAttrOutlineLevel() > nLevel); - - // get the correct end node - // the outline node may be in frames, headers, footers special section of doc model - SwNode* pStartOfSectionNodeSttNd = pSttNd->StartOfSectionNode(); - while (pStartOfSectionNodeSttNd->StartOfSectionNode() - != pStartOfSectionNodeSttNd->StartOfSectionNode()->StartOfSectionNode()) - { - pStartOfSectionNodeSttNd = pStartOfSectionNodeSttNd->StartOfSectionNode(); - } - pEndNd = pStartOfSectionNodeSttNd->EndOfSectionNode(); + // determine end node of folded outline content + SwNode* pEndNd = &rNodes.GetEndOfContent(); + if (rOutlineNodes.size() > nPos + 1) + pEndNd = rOutlineNodes[nPos + 1]; - if (iPos < rOutlineNodes.size()) - { - SwNode* pStartOfSectionNode = rOutlineNodes[iPos]->StartOfSectionNode(); - while (pStartOfSectionNode->StartOfSectionNode() - != pStartOfSectionNode->StartOfSectionNode()->StartOfSectionNode()) - { - pStartOfSectionNode = pStartOfSectionNode->StartOfSectionNode(); - } - if (pStartOfSectionNodeSttNd == pStartOfSectionNode) - pEndNd = rOutlineNodes[iPos]; - } - } + if (pThis->GetViewOptions()->IsTreatSubOutlineLevelsAsContent()) + { + // get the next outline node after the folded outline content (iPos) + // it is the next outline node with the same level or less + int nLevel = pSttNd->GetTextNode()->GetAttrOutlineLevel(); + SwOutlineNodes::size_type iPos = nPos; + while (++iPos < rOutlineNodes.size() + && rOutlineNodes[iPos]->GetTextNode()->GetAttrOutlineLevel() > nLevel) + ; - // table, text box, header, footer - if (pSttNd->GetTableBox() || pSttNd->GetIndex() < rNodes.GetEndOfExtras().GetIndex()) - { - // insert before section end node - if (pSttNd->EndOfSectionIndex() < pEndNd->GetIndex()) - { - SwNodeIndex aIdx(*pSttNd->EndOfSectionNode()); - while (aIdx.GetNode().IsEndNode()) - --aIdx; - ++aIdx; - pEndNd = &aIdx.GetNode(); - } - } - // if pSttNd isn't in table but pEndNd is then insert after table - else if (pEndNd->GetTableBox()) + // get the correct end node + // the outline node may be in frames, headers, footers special section of doc model + SwNode* pStartOfSectionNodeSttNd = pSttNd->StartOfSectionNode(); + while (pStartOfSectionNodeSttNd->StartOfSectionNode() + != pStartOfSectionNodeSttNd->StartOfSectionNode()->StartOfSectionNode()) + { + pStartOfSectionNodeSttNd = pStartOfSectionNodeSttNd->StartOfSectionNode(); + } + pEndNd = pStartOfSectionNodeSttNd->EndOfSectionNode(); + + if (iPos < rOutlineNodes.size()) + { + SwNode* pStartOfSectionNode = rOutlineNodes[iPos]->StartOfSectionNode(); + while (pStartOfSectionNode->StartOfSectionNode() + != pStartOfSectionNode->StartOfSectionNode()->StartOfSectionNode()) { - pEndNd = pEndNd->FindTableNode(); - SwNodeIndex aIdx(*pEndNd, -1); - // account for nested tables - while (aIdx.GetNode().GetTableBox()) - { - pEndNd = aIdx.GetNode().FindTableNode(); - aIdx.Assign(*pEndNd, -1); - } - aIdx.Assign(*pEndNd->EndOfSectionNode(), +1); - pEndNd = &aIdx.GetNode(); + pStartOfSectionNode = pStartOfSectionNode->StartOfSectionNode(); } - // end node determined + if (pStartOfSectionNodeSttNd == pStartOfSectionNode) + pEndNd = rOutlineNodes[iPos]; + } + } - // now insert the new outline node - SwDoc* pDoc = pThis->GetDoc(); + // table, text box, header, footer + if (pSttNd->GetTableBox() || pSttNd->GetIndex() < rNodes.GetEndOfExtras().GetIndex()) + { + // insert before section end node + if (pSttNd->EndOfSectionIndex() < pEndNd->GetIndex()) + { + SwNodeIndex aIdx(*pSttNd->EndOfSectionNode()); + while (aIdx.GetNode().IsEndNode()) + --aIdx; + ++aIdx; + pEndNd = &aIdx.GetNode(); + } + } + // if pSttNd isn't in table but pEndNd is then insert after table + else if (pEndNd->GetTableBox()) + { + pEndNd = pEndNd->FindTableNode(); + SwNodeIndex aIdx(*pEndNd, -1); + // account for nested tables + while (aIdx.GetNode().GetTableBox()) + { + pEndNd = aIdx.GetNode().FindTableNode(); + aIdx.Assign(*pEndNd, -1); + } + aIdx.Assign(*pEndNd->EndOfSectionNode(), +1); + pEndNd = &aIdx.GetNode(); + } + // end node determined - // insert at end of tablebox doesn't work correct without - MakeAllOutlineContentTemporarilyVisible a(pDoc); + // now insert the new outline node + SwDoc* pDoc = pThis->GetDoc(); - SwTextNode* pNd = pDoc->GetNodes().MakeTextNode(*pEndNd, pTextNode->GetTextColl(), true); + // insert at end of tablebox doesn't work correct without + MakeAllOutlineContentTemporarilyVisible a(pDoc); - // if the outline level is not set in style then it is set in direct formatting - if (!pTextNode->GetTextColl()->GetAttrOutlineLevel()) - pNd->SetAttrOutlineLevel(pTextNode->GetAttrOutlineLevel()); + SwTextNode* pNd = pDoc->GetNodes().MakeTextNode(*pEndNd, pTextNode->GetTextColl(), true); - (void) rOutlineNodes.Seek_Entry(pNd, &nPos); - pThis->GotoOutline(nPos); + // if the outline level is not set in style then it is set in direct formatting + if (!pTextNode->GetTextColl()->GetAttrOutlineLevel()) + pNd->SetAttrOutlineLevel(pTextNode->GetAttrOutlineLevel()); - if (pDoc->GetIDocumentUndoRedo().DoesUndo()) - { - pDoc->GetIDocumentUndoRedo().ClearRedo(); - pDoc->GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoInsert>(*pNd)); - pDoc->GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoFormatColl> - (SwPaM(*pNd), pNd->GetTextColl(), true, true)); - if (!pNd->GetTextColl()->GetAttrOutlineLevel()) - pDoc->GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoAttr>( - SwPaM(*pNd), - SfxUInt16Item(RES_PARATR_OUTLINELEVEL, pNd->GetAttrOutlineLevel()), - SetAttrMode::DEFAULT)); - } + (void)rOutlineNodes.Seek_Entry(pNd, &nPos); + pThis->GotoOutline(nPos); - pThis->SetModified(); - return true; - } + if (pDoc->GetIDocumentUndoRedo().DoesUndo()) + { + pDoc->GetIDocumentUndoRedo().ClearRedo(); + pDoc->GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoInsert>(*pNd)); + pDoc->GetIDocumentUndoRedo().AppendUndo( + std::make_unique<SwUndoFormatColl>(SwPaM(*pNd), pNd->GetTextColl(), true, true)); + if (!pTextNode->GetTextColl()->GetAttrOutlineLevel()) + pDoc->GetIDocumentUndoRedo().AppendUndo(std::make_unique<SwUndoAttr>( + SwPaM(*pNd), + SfxUInt16Item(RES_PARATR_OUTLINELEVEL, pTextNode->GetAttrOutlineLevel()), + SetAttrMode::DEFAULT)); } - return false; + + pThis->SetModified(); + return true; } // SplitNode; also, because
