sc/inc/table.hxx                |    6 +++++
 sc/qa/unit/ucalc_condformat.cxx |   41 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

New commits:
commit 7ff5692e8e0cf95a17d9e8d88a2f89af52c086e6
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Nov 23 14:13:47 2025 +0500
Commit:     Xisco Fauli <[email protected]>
CommitDate: Thu Nov 27 16:35:16 2025 +0100

    tdf#168943: Handle non-multimarked mark data
    
    Add the respective code to ScTable::Apply, which somehow got lost in
    commit b5da114b67b29c91d16f2cb618cf30e7aa1b068d (Move code applying
    functor to selection from ScColumnData to ScTable, 2025-03-15).
    
    Change-Id: I0a9b6d9695a604c091eaca4c7b4e822c4e8c8781
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194386
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194418

diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index daa255957744..e3e7c4f22ce4 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -1503,6 +1503,12 @@ void ScTable::Apply(const ScMarkData& rMark, SCCOL nCol, 
ApplyDataFunc apply)
         while (aMultiIter.Next(nTop, nBottom))
             apply(rCol, nTop, nBottom);
     }
+    else if (rMark.IsMarked())
+    {
+        const ScRange& aRange = rMark.GetMarkArea();
+        if (aRange.aStart.Col() <= nCol && nCol <= aRange.aEnd.Col())
+            apply(GetColumnData(nCol), aRange.aStart.Row(), aRange.aEnd.Row());
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx
index e470fe8f5400..faacf904e311 100644
--- a/sc/qa/unit/ucalc_condformat.cxx
+++ b/sc/qa/unit/ucalc_condformat.cxx
@@ -1523,6 +1523,47 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, 
testConditionStyleInMergedCell)
     m_pDoc->DeleteTab(0);
 }
 
+CPPUNIT_TEST_FIXTURE(TestCondformat, testTdf168943)
+{
+    m_pDoc->InsertTab(0, u"test"_ustr);
+
+    for (SCROW nRow = 0; nRow <= 5; ++nRow)
+    {
+        // Initial state: no conditional format, so attribute must be default
+        CPPUNIT_ASSERT(IsDefaultItem(m_pDoc->GetAttr(0, nRow, 0, 
ATTR_CONDITIONAL)));
+    }
+
+    auto pEntry = new ScCondFormatEntry(ScConditionMode::Direct, u"=42"_ustr, 
{}, *m_pDoc,
+                                        ScAddress(0, 0, 0), 
ScResId(STR_STYLENAME_RESULT));
+
+    auto pFormat = std::make_unique<ScConditionalFormat>(0, *m_pDoc);
+    pFormat->AddEntry(pEntry);
+    ScRange aRange(0, 0, 0, 0, 5, 0);
+    pFormat->SetRange(aRange);
+    auto key = m_pDoc->AddCondFormat(std::move(pFormat), 0);
+    m_pDoc->AddCondFormatData(aRange, 0, key);
+
+    for (SCROW nRow = 0; nRow <= 5; ++nRow)
+    {
+        // The attribute must be set
+        CPPUNIT_ASSERT(!IsDefaultItem(m_pDoc->GetAttr(0, nRow, 0, 
ATTR_CONDITIONAL)));
+    }
+
+    ScConditionalFormatList* pNewList = new ScConditionalFormatList();
+    m_xDocShell->GetDocFunc().SetConditionalFormatList(pNewList, 0);
+
+    for (SCROW nRow = 0; nRow <= 5; ++nRow)
+    {
+        // Check if respective attribute has been correctly cleared.
+        // Before the fix, this failed, because 
ScConditionalFormatList::RemoveFromDocument, called
+        // from SetConditionalFormatList, got a non-multimarked 
single-contiguous-range mark, and
+        // ScTable::Apply was not prepared for such marks, so did nothing.
+        CPPUNIT_ASSERT(IsDefaultItem(m_pDoc->GetAttr(0, nRow, 0, 
ATTR_CONDITIONAL)));
+    }
+
+    m_pDoc->DeleteTab(0);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to