sw/qa/uibase/wrtsh/data/tdf58511.odt |binary
 sw/qa/uibase/wrtsh/wrtsh.cxx         |   77 +++++++++++++++++++++++++++++++++++
 sw/source/uibase/wrtsh/delete.cxx    |    2 
 3 files changed, 79 insertions(+)

New commits:
commit e61b6a9709370b07ce8c81ea596d1f8eff941928
Author:     Buo-ren Lin (OSSII) <buoren....@ossii.com.tw>
AuthorDate: Thu Jul 3 09:35:20 2025 +0800
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Jul 29 06:00:02 2025 +0200

    tdf#58511 sw: Fix source fontwork object not removed after being cut
    
    In the `SwWrtShell::DelRight` class method where the cut operation logic
    will call, the `GetSelectionType()` call returned `0x10200` for this
    object, which is a bitwise OR-ed value of `SelectionType::FontWork` and
    `SelectionType::DrawObject` taht is assigned to the `nSelection`
    variable. The variable won't match any cases in the subsequent `switch`
    statement where the object removal operation will be done as all the
    cases only match a single `SelectionType` value.
    
    This patch adds a `if` statement to set the `nSelection` variable
    to `SelectionType::DrawObject` when the object is a FontWork, making
    it enter the intended logic to handle such an object's deletion.
    
    Co-authored-by: Franklin Weng <frank...@goodhorse.idv.tw>
    Signed-off-by: Buo-ren Lin (OSSII) <buoren....@ossii.com.tw>
    Reviewed-by: Franklin Weng <frank...@goodhorse.idv.tw>
    Change-Id: I8074a98be9d10fc26f8d498abfe94b011cc97eb0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187294
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/uibase/wrtsh/data/tdf58511.odt 
b/sw/qa/uibase/wrtsh/data/tdf58511.odt
new file mode 100644
index 000000000000..be6153ab9358
Binary files /dev/null and b/sw/qa/uibase/wrtsh/data/tdf58511.odt differ
diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx
index 5684c3670704..1fea0e84b1c7 100644
--- a/sw/qa/uibase/wrtsh/wrtsh.cxx
+++ b/sw/qa/uibase/wrtsh/wrtsh.cxx
@@ -34,6 +34,14 @@
 #include <formatflysplit.hxx>
 #include <frmatr.hxx>
 
+#include <svx/fontworkbar.hxx>
+#include <svx/svdpage.hxx>
+#include <svx/svdobj.hxx>
+#include <svx/svdview.hxx>
+#include <drawdoc.hxx>
+#include <IDocumentDrawModelAccess.hxx>
+#include <swdtflvr.hxx>
+
 namespace
 {
 /// Covers sw/source/uibase/wrtsh/ fixes.
@@ -577,6 +585,75 @@ CPPUNIT_TEST_FIXTURE(Test, testRemoveIndent)
     // i.e. there was no decrease of the left text margin on pressing 
backspace.
     CPPUNIT_ASSERT_EQUAL(static_cast<SwTwips>(1135), nLeftMargin);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testCutFontworkObject)
+{
+    // Given a document with a fontwork object named "fontwork1":
+    createSwDoc("tdf58511.odt");
+    SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+    SwDoc* pDoc = getSwDoc();
+
+    // First, verify that the fontwork object exists
+    SwDrawModel* pDrawModel = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel();
+    SdrPage* pPage = pDrawModel->GetPage(0);
+    SdrObject* pFontworkObj = nullptr;
+
+    // Search for the fontwork object by name
+    for (size_t i = 0; i < pPage->GetObjCount(); ++i)
+    {
+        SdrObject* pObj = pPage->GetObj(i);
+        if (pObj && pObj->GetName() == u"fontwork1")
+        {
+            // Check if it's actually a fontwork object using the helper 
function
+            if (svx::checkForFontWork(pObj))
+            {
+                pFontworkObj = pObj;
+                break;
+            }
+        }
+    }
+
+    // Make sure the fontwork object was found initially
+    CPPUNIT_ASSERT(pFontworkObj != nullptr);
+
+    // Select the fontwork object
+    SdrView* pSdrView = pWrtShell->GetDrawView();
+    CPPUNIT_ASSERT(pSdrView != nullptr);
+
+    // Clear any existing selection
+    pSdrView->UnmarkAll();
+
+    // Mark the fontwork object
+    pSdrView->MarkObj(pFontworkObj, pSdrView->GetSdrPageView());
+
+    // Verify the object is selected
+    const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rMarkList.GetMarkCount());
+    CPPUNIT_ASSERT_EQUAL(pFontworkObj, 
rMarkList.GetMark(0)->GetMarkedSdrObj());
+
+    // When cutting the fontwork object - use SwTransferable::Copy with bIsCut 
= true:
+    rtl::Reference<SwTransferable> xTransfer(new SwTransferable(*pWrtShell));
+    xTransfer->Cut();
+
+    // Then make sure the fontwork object is deleted from the document:
+    pFontworkObj = nullptr;
+    for (size_t i = 0; i < pPage->GetObjCount(); ++i)
+    {
+        SdrObject* pObj = pPage->GetObj(i);
+        if (pObj && pObj->GetName() == u"fontwork1")
+        {
+            if (svx::checkForFontWork(pObj))
+            {
+                pFontworkObj = pObj;
+                break;
+            }
+        }
+    }
+
+    // Without the accompanying fix in place, this test would have failed 
because
+    // the fontwork object was not properly deleted when cut.
+    CPPUNIT_ASSERT(pFontworkObj == nullptr);
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/uibase/wrtsh/delete.cxx 
b/sw/source/uibase/wrtsh/delete.cxx
index 8d0d4f3c7c1f..ea7c6d07e63b 100644
--- a/sw/source/uibase/wrtsh/delete.cxx
+++ b/sw/source/uibase/wrtsh/delete.cxx
@@ -295,6 +295,8 @@ bool SwWrtShell::DelRight(bool const isReplaceHeuristic)
         nSelection = SelectionType::Table;
     if(nSelection & SelectionType::Text)
         nSelection = SelectionType::Text;
+    if(nSelection & SelectionType::FontWork)
+        nSelection = SelectionType::DrawObject;
 
     switch( nSelection & ~SelectionType::Ornament & ~SelectionType::Media )
     {

Reply via email to