sc/qa/unit/tiledrendering/SheetViewTest.cxx | 73 ++++++++++ sc/qa/unit/tiledrendering/data/SheetView_AutoFilter_Extended.ods |binary sc/source/ui/operation/SortOperation.cxx | 22 ++- 3 files changed, 94 insertions(+), 1 deletion(-)
New commits: commit 72e0c60c07889f6033f10df6883fcfb59fb76d7f Author: Tomaž Vajngerl <[email protected]> AuthorDate: Thu Feb 19 22:12:40 2026 +0900 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Feb 20 14:39:51 2026 +0100 sc: add sheet view syncing to SortOperation This implements syncing the sorting, when this is expected. If the range that we are sorting is the auto-filtered range, then we only sort the current view (either sheet view of the default view) and no syncing is required. If the sorted range is not the auto-filtered range, then we need to sync the change with all views, similar to other operations. Change-Id: Id5c3caa984fb8b1250ac148ee4bfd01bc97f65c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199721 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sc/qa/unit/tiledrendering/SheetViewTest.cxx b/sc/qa/unit/tiledrendering/SheetViewTest.cxx index 246366e8f8cc..589d801a609e 100644 --- a/sc/qa/unit/tiledrendering/SheetViewTest.cxx +++ b/sc/qa/unit/tiledrendering/SheetViewTest.cxx @@ -1560,6 +1560,79 @@ CPPUNIT_TEST_FIXTURE(SyncTest, testCreateAndDeleteSheetView) } } +CPPUNIT_TEST_FIXTURE(SyncTest, testSorting_NonAutoFilterRange) +{ + // When we sort outside of the auto-filtered range, we sync the changes + // to all views. When sorting auto-filtered range, then we sort only the + // current view and don't sync. + + ScModelObj* pModelObj = createDoc("SheetView_AutoFilter_Extended.ods"); + pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>()); + ScDocument& rDocument = *pModelObj->GetDocument(); + + setupViews(); + + // Check sorting when no sheet view was created yet + { + switchToDefaultView(); + + // Check we have no sheet view yet + auto pSheetViewManager = rDocument.GetSheetViewManager(SCTAB(0)); + CPPUNIT_ASSERT(pSheetViewManager); + CPPUNIT_ASSERT(pSheetViewManager->isEmpty()); + + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"4", u"5", u"3", u"7" }), + getValues(mpTabViewDefaultView, 0, 1, 4)); + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"ccc", u"rrr", u"sss", u"aaa" }), + getValues(mpTabViewDefaultView, 1, 1, 4)); + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"44", u"22", u"11", u"33" }), + getValues(mpTabViewDefaultView, 4, 1, 4)); + + // Select and sort the range - no sheet views yet + sortDescendingForCell(u"E2:E5"); + + // Check - we expect to be sorted descending + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"44", u"33", u"22", u"11" }), + getValues(mpTabViewDefaultView, 4, 1, 4)); + } + + // Check sheet view sorting + { + switchToSheetView(); + createNewSheetViewInCurrentView(); + + // Check initial values of the E2:E5 range + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"44", u"33", u"22", u"11" }), + getValues(mpTabViewSheetView, 4, 1, 4)); + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"44", u"33", u"22", u"11" }), + getValues(mpTabViewDefaultView, 4, 1, 4)); + + // Sort the range ascending + sortAscendingForCell(u"E2:E5"); + + // Check - we expect both views to be sorted ascending + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"11", u"22", u"33", u"44" }), + getValues(mpTabViewSheetView, 4, 1, 4)); + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"11", u"22", u"33", u"44" }), + getValues(mpTabViewDefaultView, 4, 1, 4)); + + // Check the auto-filtered values in column B + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"ccc", u"rrr", u"sss", u"aaa" }), + getValues(mpTabViewSheetView, 1, 1, 4)); + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"ccc", u"rrr", u"sss", u"aaa" }), + getValues(mpTabViewDefaultView, 1, 1, 4)); + + // Select the range of an auto-filtered range and sort ascending column B + sortAscendingForCell(u"B1"); + + // Check - only the sheet view should be sorted + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"aaa", u"ccc", u"rrr", u"sss" }), + getValues(mpTabViewSheetView, 1, 1, 4)); + CPPUNIT_ASSERT_EQUAL(expectedValues({ u"ccc", u"rrr", u"sss", u"aaa" }), + getValues(mpTabViewDefaultView, 1, 1, 4)); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/tiledrendering/data/SheetView_AutoFilter_Extended.ods b/sc/qa/unit/tiledrendering/data/SheetView_AutoFilter_Extended.ods new file mode 100644 index 000000000000..fd93d5d9e9cb Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/SheetView_AutoFilter_Extended.ods differ diff --git a/sc/source/ui/operation/SortOperation.cxx b/sc/source/ui/operation/SortOperation.cxx index a01af92b6025..13a33e6de95f 100644 --- a/sc/source/ui/operation/SortOperation.cxx +++ b/sc/source/ui/operation/SortOperation.cxx @@ -57,12 +57,28 @@ bool SortOperation::runImplementation() return false; } + ScSortParam aLocalParam(mrSortParam); + + // If we are in a sheet view and aren't sorting auto-filtered cell range, we need + // to sync the sorted cells. If this is the case then we need to convert the tab + // from the sheet view tab to default view tab. + if (mpViewData && rDoc.IsSheetViewHolder(mnTab) && !pDBData->HasAutoFilter()) + { + SCTAB nSheetViewTab = mnTab; + mnTab = mpViewData->GetTabNumber(); + + if (aLocalParam.nSourceTab == nSheetViewTab) + aLocalParam.nSourceTab = mnTab; + + if (aLocalParam.nDestTab == nSheetViewTab) + aLocalParam.nDestTab = mnTab; + } + bool bCopy = !mrSortParam.bInplace; if (bCopy && mrSortParam.nDestCol == mrSortParam.nCol1 && mrSortParam.nDestRow == mrSortParam.nRow1 && mrSortParam.nDestTab == mnTab) bCopy = false; - ScSortParam aLocalParam(mrSortParam); if (bCopy) { // Copy the data range to the destination then move the sort range to it. @@ -254,6 +270,10 @@ bool SortOperation::runImplementation() if (!bUniformRowHeight && nStartRow <= nOverallRow2) mrDocShell.AdjustRowHeight(nStartRow, nOverallRow2, mnTab); + // Perform syncing, but only if we don't sort the auto-filtered cell range + if (!pDBData->HasAutoFilter()) + syncSheetViews(); + aModificator.SetDocumentModified(); return true;
