sw/qa/extras/uiwriter/uiwriter2.cxx | 46 +++++++++++++++++++++++++++++++++++ sw/source/uibase/dochdl/swdtflvr.cxx | 31 +++++++++++++++++------ 2 files changed, 69 insertions(+), 8 deletions(-)
New commits: commit 5e8aa259e48d5602b932353bb146ebb523982cf2 Author: László Németh <nem...@numbertext.org> AuthorDate: Mon Jan 24 17:37:09 2022 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Tue Jan 25 12:18:23 2022 +0100 tdf#146967 sw table: fix freezing in Hide Changes mode During change tracking, drag & drop or Cut & Paste a table row resulted freezing in Hide Changes mode. Test: In Hide Changes mode, select a table row by clicking on their left border, and drag & drop or Cut & Paste it in a different table row. Regression from commit 5a1c19624eda0c8b847af0dcee70b82502578ceb. Follow-up to commit 5a1c19624eda0c8b847af0dcee70b82502578ceb tdf#146965 sw track changes: fix tracked table row moving Change-Id: Iab606ce036fedcc70e42638e3ccf804c9dbca064 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128875 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 157891b1b363..a1fc810fafec 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -5110,6 +5110,52 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testPasteTrackedTableRow) CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testPasteTrackedTableRowInHideChangesMode) +{ + // load a 1-row table + SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf118311.fodt"); + + // turn on red-lining and show changes + pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On); + CPPUNIT_ASSERT_MESSAGE("redlining should be on", + pDoc->getIDocumentRedlineAccess().IsRedlineOn()); + CPPUNIT_ASSERT_MESSAGE("redlines should be invisible", + !IDocumentRedlineAccess::IsShowChanges( + pDoc->getIDocumentRedlineAccess().GetRedlineFlags())); + + // check table count + uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + + // check table row count + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount()); + + // copy table row and paste it by Paste Special->Rows Above + dispatchCommand(mxComponent, ".uno:SelectTable", {}); + dispatchCommand(mxComponent, ".uno:Copy", {}); + dispatchCommand(mxComponent, ".uno:Escape", {}); + + // This resulted freezing + dispatchCommand(mxComponent, ".uno:PasteRowsBefore", {}); + + // 2-row table + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount()); + + // This was 2 (inserted as a nested table in the first cell of the new row) + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + + dispatchCommand(mxComponent, ".uno:Undo", {}); + dispatchCommand(mxComponent, ".uno:Undo", {}); + dispatchCommand(mxComponent, ".uno:Undo", {}); // FIXME Why 3 Undos? + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRows()->getCount()); + + dispatchCommand(mxComponent, ".uno:Redo", {}); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf145091) { // load a deleted table, reject them, and delete only its text and export to DOCX diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index c3047586acd7..883ada5147b8 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -1619,8 +1619,8 @@ bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndSt bool bResult = SwTransferable::PasteData( rData, rSh, nAction, nActionFlags, nFormat, nDestination, false, false, nullptr, 0, false, nAnchorType, bIgnoreComments, &aPasteContext ); - // set tracked insertion - if ( eOld & RedlineFlags::On ) + // set tracked insertion, if it's not in a drag & drop action + if ( !rSh.ActionPend() && ( eOld & RedlineFlags::On) ) { SvxPrintItem aTracked(RES_PRINT, false); rSh.GetDoc()->SetRowNotTracked( *rSh.GetCursor(), aTracked ); @@ -3925,6 +3925,11 @@ bool SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt, { bool bTableCol(SelectionType::TableCol & nSelection); + ::sw::mark::IMark* pMarkMoveFrom = rSh.SetBookmark( + vcl::KeyCode(), + OUString(), + IDocumentMarkAccess::MarkType::UNO_BOOKMARK ); + SwUndoId eUndoId = bMove ? SwUndoId::UI_DRAG_AND_MOVE : SwUndoId::UI_DRAG_AND_COPY; SwRewriter aRewriter; @@ -3951,11 +3956,27 @@ bool SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt, OUString(), IDocumentMarkAccess::MarkType::UNO_BOOKMARK ); + // paste rows above/columns before + pDispatch->Execute(bTableCol ? FN_TABLE_PASTE_COL_BEFORE : FN_TABLE_PASTE_ROW_BEFORE, SfxCallMode::SYNCHRON); + + // go to the previously inserted table row and set it to tracked insertion + rSh.Up(false); + SvxPrintItem aTracked(RES_PRINT, false); + rSh.GetDoc()->SetRowNotTracked( *rSh.GetCursor(), aTracked ); + rSrcSh.Pop(SwCursorShell::PopMode::DeleteCurrent); // restore selection... // delete source rows/columns if (bMove) + { + // restore cursor position + if (pMarkMoveFrom != nullptr) + { + rSh.GotoMark( pMarkMoveFrom ); + rSh.getIDocumentMarkAccess()->deleteMark( pMarkMoveFrom ); + } pDispatch->Execute(bTableCol ? FN_TABLE_DELETE_COL : FN_TABLE_DELETE_ROW, SfxCallMode::SYNCHRON); + } // restore cursor position if (pMark != nullptr) @@ -3964,12 +3985,6 @@ bool SwTransferable::PrivateDrop( SwWrtShell& rSh, const Point& rDragPt, rSh.getIDocumentMarkAccess()->deleteMark( pMark ); } - // paste rows above/columns before - pDispatch->Execute(bTableCol ? FN_TABLE_PASTE_COL_BEFORE : FN_TABLE_PASTE_ROW_BEFORE, SfxCallMode::SYNCHRON); - - if( rSrcSh.GetDoc() != rSh.GetDoc() ) - rSrcSh.EndUndo(); - rSh.DestroyCursor(); rSh.EndUndo(); rSh.EndAction();