sw/qa/extras/uiwriter/uiwriter5.cxx | 84 ++++++++++++++++++++++++++++++++++++ sw/source/core/edit/ednumber.cxx | 21 ++++----- 2 files changed, 95 insertions(+), 10 deletions(-)
New commits: commit 9a2e7bade3aa8b115f1973be532ec86fa0369171 Author: Justin Luth <jl...@mail.com> AuthorDate: Mon May 23 18:33:41 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Jun 13 09:51:35 2022 +0200 tdf#145151 sw IsTableMode NumRule: unselected cells ...should not be affected when setting or deleting numbering. This patch depends on follow-up patches to properly detect if numbering is turned on or off in some cases. This patch prevents numbering from "leaking" into the previous cell if the cells were selected backwards. Perhaps it would be better to fix the selection code itself instead of handling all of these edge cases, but doing that might have unintended consequences that I wouldn't have any insight into. So this is safer. Change-Id: I98e18d6056e93a4d89fdbe75b6237daca7832f41 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134885 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx b/sw/qa/extras/uiwriter/uiwriter5.cxx index 1e9d5a0b7560..6517b7a32557 100644 --- a/sw/qa/extras/uiwriter/uiwriter5.cxx +++ b/sw/qa/extras/uiwriter/uiwriter5.cxx @@ -2870,6 +2870,90 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf93747) getProperty<OUString>(getParagraphOfText(1, xCellB1->getText()), "ParaStyleName")); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf145151) +{ + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtSh = pDoc->GetDocShell()->GetWrtShell(); + + uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence( + { { "Rows", uno::Any(sal_Int32(2)) }, { "Columns", uno::Any(sal_Int32(2)) } })); + + dispatchCommand(mxComponent, ".uno:InsertTable", aArgs); + Scheduler::ProcessEventsToIdle(); + + pWrtSh->Insert("Col1"); + + // Move the cursor to B1 + pWrtSh->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); + + pWrtSh->Insert("Col2"); + + uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTextTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getRows()->getCount()); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getColumns()->getCount()); + + uno::Reference<text::XTextRange> xCellA1(xTextTable->getCellByName("A1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Col1"), xCellA1->getString()); + + uno::Reference<text::XTextRange> xCellB1(xTextTable->getCellByName("B1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("Col2"), xCellB1->getString()); + + // Select backwards B1 and A1 (select "2loC<cell>" which ends up selecting both cells) + pWrtSh->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 5, /*bBasicCall=*/false); + + // Just select the whole B1 + pWrtSh->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); + + dispatchCommand(mxComponent, ".uno:DefaultNumbering", {}); + Scheduler::ProcessEventsToIdle(); + + // B1 should now have a numbering style, but A1 should not be affected. + OUString sNumStyleB1 + = getProperty<OUString>(getParagraphOfText(1, xCellB1->getText()), "NumberingStyleName"); + CPPUNIT_ASSERT(!sNumStyleB1.isEmpty()); + CPPUNIT_ASSERT_MESSAGE( + "Only cell B1 was selected. A1 should not have any numbering.", + getProperty<OUString>(getParagraphOfText(1, xCellA1->getText()), "NumberingStyleName") + .isEmpty()); + + // Now test removing numbering/bullets + // Add A1 to the current B1 selection + pWrtSh->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); + + // Toggle on bullet numbering + dispatchCommand(mxComponent, ".uno:DefaultBullet", {}); + Scheduler::ProcessEventsToIdle(); + + // sanity check - both cells have bullets turned on. + OUString sNumStyleA1 + = getProperty<OUString>(getParagraphOfText(1, xCellA1->getText()), "NumberingStyleName"); + CPPUNIT_ASSERT(!sNumStyleA1.isEmpty()); + CPPUNIT_ASSERT_EQUAL( + sNumStyleA1, + getProperty<OUString>(getParagraphOfText(1, xCellB1->getText()), "NumberingStyleName")); + CPPUNIT_ASSERT(sNumStyleA1 != sNumStyleB1); // therefore B1 changed from numbering to bullets + + // Just select cell B1 + pWrtSh->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); + + // Toggle off bullet numbering + dispatchCommand(mxComponent, ".uno:DefaultBullet", {}); + Scheduler::ProcessEventsToIdle(); + + // B1 should now have removed all numbering, while A1 should still have the bullet. + CPPUNIT_ASSERT( + getProperty<OUString>(getParagraphOfText(1, xCellB1->getText()), "NumberingStyleName") + .isEmpty()); + CPPUNIT_ASSERT_MESSAGE( + "Only cell B1 was selected. A1 should still have bullets turned on.", + !getProperty<OUString>(getParagraphOfText(1, xCellA1->getText()), "NumberingStyleName") + .isEmpty()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf126735) { SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf39721.fodt"); diff --git a/sw/source/core/edit/ednumber.cxx b/sw/source/core/edit/ednumber.cxx index 3304ddb19435..3b35eab94c57 100644 --- a/sw/source/core/edit/ednumber.cxx +++ b/sw/source/core/edit/ednumber.cxx @@ -274,11 +274,12 @@ void SwEditShell::DelNumRules() if( pCursor->IsMultiSelection() ) { GetDoc()->GetIDocumentUndoRedo().StartUndo( SwUndoId::START, nullptr ); - SwPamRanges aRangeArr( *pCursor ); - SwPaM aPam( *pCursor->GetPoint() ); - for( size_t n = 0; n < aRangeArr.Count(); ++n ) + for (SwPaM& rPaM : pCursor->GetRingContainer()) { - GetDoc()->DelNumRules(aRangeArr.SetPam( n, aPam ), GetLayout()); + if (IsTableMode() && !rPaM.HasMark()) + continue; + + GetDoc()->DelNumRules(rPaM, GetLayout()); } GetDoc()->GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr ); } @@ -769,13 +770,13 @@ void SwEditShell::SetCurNumRule( const SwNumRule& rRule, SwPaM* pCursor = GetCursor(); if( IsMultiSelection() ) { - SwPamRanges aRangeArr( *pCursor ); - SwPaM aPam( *pCursor->GetPoint() ); OUString sContinuedListId(rContinuedListId); - for( size_t n = 0; n < aRangeArr.Count(); ++n ) + for (SwPaM& rPaM : pCursor->GetRingContainer()) { - aRangeArr.SetPam( n, aPam ); - OUString sListId = GetDoc()->SetNumRule( aPam, rRule, + if (IsTableMode() && !rPaM.HasMark()) + continue; + + OUString sListId = GetDoc()->SetNumRule(rPaM, rRule, bCreateNewList, GetLayout(), sContinuedListId, true, bResetIndentAttrs ); @@ -787,7 +788,7 @@ void SwEditShell::SetCurNumRule( const SwNumRule& rRule, bCreateNewList = false; } - GetDoc()->SetCounted(aPam, true, GetLayout()); + GetDoc()->SetCounted(rPaM, true, GetLayout()); } } else