sw/qa/extras/uiwriter/uiwriter5.cxx | 8 ++ sw/source/core/edit/ednumber.cxx | 99 ++++++++++++++++-------------------- 2 files changed, 52 insertions(+), 55 deletions(-)
New commits: commit 5036c5a7afdd043c3fa5c108c985cd0d8ed352fa Author: Justin Luth <jl...@mail.com> AuthorDate: Mon May 23 19:05:20 2022 +0200 Commit: Justin Luth <jl...@mail.com> CommitDate: Wed Jun 15 01:28:51 2022 +0200 tdf#145151 sw IsTableMode SelectionHasNumber: unselected cells ...shouldn't be checked This followup patch checks the proper cells to see if numbering or bullets are turned on. There is one side effect here. Picture this scenario where you select some paragraphs (_ indicates blank paragraph) _ _ 1. some numbered text _ In this non-empty case, SectionHasNumber is true, showing numbering on in the toolbar. Prior to this patch, the following scenario was "false", showing numbering off in the toolbar. - - 1._ _ and the result was that all the blank lines toggled on. Now it acts just like the non-empty case. Although one can dispute that this is the correct action, consistency is nice... Change-Id: I8a1b8ee0fe947a7bfe7906a0add3aaf2d8e7b232 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134886 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx b/sw/qa/extras/uiwriter/uiwriter5.cxx index 6517b7a32557..c88dd905f584 100644 --- a/sw/qa/extras/uiwriter/uiwriter5.cxx +++ b/sw/qa/extras/uiwriter/uiwriter5.cxx @@ -2952,6 +2952,14 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf145151) "Only cell B1 was selected. A1 should still have bullets turned on.", !getProperty<OUString>(getParagraphOfText(1, xCellA1->getText()), "NumberingStyleName") .isEmpty()); + + // Toggle it back on + dispatchCommand(mxComponent, ".uno:DefaultBullet", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT( + !getProperty<OUString>(getParagraphOfText(1, xCellB1->getText()), "NumberingStyleName") + .isEmpty()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf126735) diff --git a/sw/source/core/edit/ednumber.cxx b/sw/source/core/edit/ednumber.cxx index 3b35eab94c57..93e0de0a4c2c 100644 --- a/sw/source/core/edit/ednumber.cxx +++ b/sw/source/core/edit/ednumber.cxx @@ -146,45 +146,40 @@ void SwEditShell::NoNum() EndAllAction(); } +// The entire selection is numbered (ignoring unnumbered empty lines) bool SwEditShell::SelectionHasNumber() const { - bool bResult = HasNumber(); - const SwTextNode * pTextNd = sw::GetParaPropsNode(*GetLayout(), GetCursor()->GetPoint()->nNode); - if (!bResult && pTextNd && pTextNd->Len()==0 && !pTextNd->GetNumRule()) { - SwPamRanges aRangeArr( *GetCursor() ); - SwPaM aPam( *GetCursor()->GetPoint() ); - for( size_t n = 0; n < aRangeArr.Count(); ++n ) + bool bResult = false; + for (SwPaM& rPaM : GetCursor()->GetRingContainer()) + { + // If in table cells select mode, ignore the cells that aren't actually selected + if (IsTableMode() && !rPaM.HasMark()) + continue; + + SwNodeOffset nStt = rPaM.Start()->nNode.GetIndex(); + SwNodeOffset nEnd = rPaM.End()->nNode.GetIndex(); + for (SwNodeOffset nPos = nStt; nPos<=nEnd; nPos++) { - aRangeArr.SetPam( n, aPam ); + SwTextNode* pTextNd = mxDoc->GetNodes()[nPos]->GetTextNode(); + if (pTextNd) { - SwNodeOffset nStt = aPam.Start()->nNode.GetIndex(), - nEnd = aPam.End()->nNode.GetIndex(); - for (SwNodeOffset nPos = nStt; nPos<=nEnd; nPos++) - { - pTextNd = mxDoc->GetNodes()[nPos]->GetTextNode(); - if (pTextNd) - { - pTextNd = sw::GetParaPropsNode(*GetLayout(), SwNodeIndex(*pTextNd)); - } - if (pTextNd && pTextNd->Len()!=0) - { - bResult = pTextNd->HasNumber(); + pTextNd = sw::GetParaPropsNode(*GetLayout(), SwNodeIndex(*pTextNd)); + } + if (pTextNd && (!bResult || pTextNd->Len()!=0)) + { + bResult = pTextNd->HasNumber(); - // #b6340308# special case: outline numbered, not counted paragraph - if ( bResult && - pTextNd->GetNumRule() == GetDoc()->GetOutlineNumRule() && - !pTextNd->IsCountedInList() ) - { - bResult = false; - } - if (!bResult) { - break; - } - } + // #b6340308# special case: outline numbered, not counted paragraph + if (bResult && + pTextNd->GetNumRule() == GetDoc()->GetOutlineNumRule() && + !pTextNd->IsCountedInList()) + { + bResult = false; } + if (!bResult && pTextNd->Len()) + break; } } - } return bResult; @@ -193,33 +188,27 @@ bool SwEditShell::SelectionHasNumber() const // add a new function to determine number on/off status bool SwEditShell::SelectionHasBullet() const { - bool bResult = HasBullet(); - const SwTextNode * pTextNd = sw::GetParaPropsNode(*GetLayout(), GetCursor()->GetPoint()->nNode); - if (!bResult && pTextNd && pTextNd->Len()==0 && !pTextNd->GetNumRule()) { - SwPamRanges aRangeArr( *GetCursor() ); - SwPaM aPam( *GetCursor()->GetPoint() ); - for( size_t n = 0; n < aRangeArr.Count(); ++n ) + bool bResult = false; + for (SwPaM& rPaM : GetCursor()->GetRingContainer()) + { + if (IsTableMode() && !rPaM.HasMark()) + continue; + + SwNodeOffset nStt = rPaM.Start()->nNode.GetIndex(); + SwNodeOffset nEnd = rPaM.End()->nNode.GetIndex(); + for (SwNodeOffset nPos = nStt; nPos<=nEnd; nPos++) { - aRangeArr.SetPam( n, aPam ); + SwTextNode* pTextNd = mxDoc->GetNodes()[nPos]->GetTextNode(); + if (pTextNd) { - SwNodeOffset nStt = aPam.Start()->nNode.GetIndex(), - nEnd = aPam.End()->nNode.GetIndex(); - for (SwNodeOffset nPos = nStt; nPos<=nEnd; nPos++) - { - pTextNd = mxDoc->GetNodes()[nPos]->GetTextNode(); - if (pTextNd) - { - pTextNd = sw::GetParaPropsNode(*GetLayout(), SwNodeIndex(*pTextNd)); - } - if (pTextNd && pTextNd->Len()!=0) - { - bResult = pTextNd->HasBullet(); + pTextNd = sw::GetParaPropsNode(*GetLayout(), SwNodeIndex(*pTextNd)); + } + if (pTextNd && (!bResult || pTextNd->Len()!=0)) + { + bResult = pTextNd->HasBullet(); - if (!bResult) { - break; - } - } - } + if (!bResult && pTextNd->Len()) + break; } } }