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/+/201891
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Miklos Vajna
2026-03-17 16:42:31 +01:00
parent 0501555403
commit 48621c0f0f
2 changed files with 38 additions and 2 deletions
+36
View File
@@ -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: */
+2 -2
View File
@@ -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;
void SortChapters(const SwOutlineNodes::size_type nOutlineNodePos = SwOutlineNodes::npos);