sw/qa/uibase/wrtsh/wrtsh.cxx   |   36 ++++++++++++++++++++++++++++++++++++
 sw/source/uibase/inc/wrtsh.hxx |    4 ++--
 2 files changed, 38 insertions(+), 2 deletions(-)

New commits:
commit 9adbd8318ebcb272586bfe622b302e1416ea0b47
Author:     Miklos Vajna <[email protected]>
AuthorDate: Fri Mar 6 13:13:54 2026 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Fri Mar 6 14:22:42 2026 +0100

    sw: fix the LOK text selection callback for multi-selections
    
    Fails with commit 53d2155bce08506c8d4f3faa052cee5ff1f689cf (Writer: Fix
    empty selection callback., 2026-03-04) reverted.
    
    Change-Id: Id966eff07b5461ab1f681349f1ed2d33129d8153
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201120
    Tested-by: Caolán McNamara <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx
index 1fea0e84b1c7..2104eabb5f04 100644
--- a/sw/qa/uibase/wrtsh/wrtsh.cxx
+++ b/sw/qa/uibase/wrtsh/wrtsh.cxx
@@ -15,11 +15,14 @@
 #include <com/sun/star/text/XTextRange.hpp>
 #include <com/sun/star/text/XTextDocument.hpp>
 
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/lok.hxx>
 #include <rtl/ustring.hxx>
 #include <sal/types.h>
 #include <comphelper/propertyvalue.hxx>
 #include <editeng/fontitem.hxx>
 #include <editeng/lrspitem.hxx>
+#include <sfx2/lokhelper.hxx>
 
 #include <swmodeltestbase.hxx>
 #include <doc.hxx>
@@ -27,6 +30,7 @@
 #include <formatlinebreak.hxx>
 #include <ndtxt.hxx>
 #include <textcontentcontrol.hxx>
+#include <unotxdoc.hxx>
 #include <fmtanchr.hxx>
 #include <view.hxx>
 #include <itabenum.hxx>
@@ -656,6 +660,38 @@ CPPUNIT_TEST_FIXTURE(Test, testCutFontworkObject)
 }
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testMultiSelectionTextSelectionCallback)
+{
+    // Given a document with "ABC" and LOK active:
+    comphelper::LibreOfficeKit::setActive(true);
+    createSwDoc();
+    SwXTextDocument* pTextDocument = getSwTextDoc();
+    
pTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+    SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+    int nViewId = SfxLokHelper::getView(*pWrtShell->GetSfxViewShell());
+    pWrtShell->Insert(u"ABC"_ustr);
+    pWrtShell->SttEndDoc(/*bStt=*/true);
+
+    // When having a multi-selection: "A" is selected and also the cursor is 
after "B":
+    pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 1, 
/*bBasicCall=*/false);
+    // Move past "B" without selecting (ctrl+click equivalent):
+    pWrtShell->EnterAddMode();
+    pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+
+    // Then the LOK text selection payload should not be empty:
+    std::optional<OString> aPayload
+        = pWrtShell->getLOKPayload(LOK_CALLBACK_TEXT_SELECTION, nViewId);
+    CPPUNIT_ASSERT(aPayload.has_value());
+    // Without the fix in place, this test would have failed, only the 
non-range "after B" selection
+    // was part of the payload.
+    CPPUNIT_ASSERT(!aPayload->isEmpty());
+
+    // Tear down LOK:
+    mxComponent->dispose();
+    mxComponent.clear();
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx
index 24e9c2a62131..c6f00aa9d2aa 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -166,7 +166,7 @@ public:
     void    ToggleExtMode();
     bool    IsExtMode() const { return m_bExtMode; }
 
-    void    EnterAddMode();
+    SW_DLLPUBLIC void EnterAddMode();
     void    LeaveAddMode();
     void    ToggleAddMode();
     bool    IsAddMode() const { return m_bAddMode; }
@@ -537,7 +537,7 @@ typedef bool (SwWrtShell::*FNSimpleMove)();
     void SetEnteringStdMode(bool bEnteringStdMode) { m_bEnteringStdMode = 
bEnteringStdMode; }
     bool IsEnteringStdMode() const { return m_bEnteringStdMode; }
 
-    std::optional<OString> getLOKPayload(int nType, int nViewId) const;
+    SW_DLLPUBLIC std::optional<OString> getLOKPayload(int nType, int nViewId) 
const;
 
 private:
 

Reply via email to