cool#15908 engine sc, SetHyperlink: ignore given text when there is a selection
Similar to commit 277ebe4cdc9ce386e9baedc687f67498b8c60cba (cool#15908 engine sw, SetHyperlink: ignore given text when there is a selection, 2026-06-02), but this one is for Calc. Signed-off-by: Miklos Vajna <vmiklos@collabora.com> Change-Id: I188151eb0961d35e1bd54cad6456b05111a49a7b Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/3794 Tested-by: Jenkins CPCI <releng@collaboraoffice.com> Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> (cherry picked from commit 8abc9830bf357dd1248a01ca33ebc2aed250ce62) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/206212 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Tested-by: Jenkins
This commit is contained in:
committed by
Xisco Fauli
parent
cebff7400f
commit
91d39664a8
@@ -11,6 +11,8 @@
|
||||
|
||||
#include <comphelper/compbase.hxx>
|
||||
#include <editeng/brushitem.hxx>
|
||||
#include <editeng/editobj.hxx>
|
||||
#include <editeng/flditem.hxx>
|
||||
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
||||
#include <sot/exchange.hxx>
|
||||
#include <svx/svdpage.hxx>
|
||||
@@ -2295,6 +2297,41 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testSpillMatrixContractionOnEdit)
|
||||
CPPUNIT_ASSERT_EQUAL(CELLTYPE_NONE, pDoc->GetCellType(ScAddress(3, 4, 0))); // D5 cleared
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testSetHyperlinkKeepSelection)
|
||||
{
|
||||
// Given a Calc doc with "foo" in cell A1 and the cell cursor on A1:
|
||||
createScDoc();
|
||||
ScDocument* pDoc = getScDoc();
|
||||
pDoc->SetString(ScAddress(0, 0, 0), u"foo"_ustr);
|
||||
goToCell(u"A1"_ustr);
|
||||
|
||||
// When dispatching .uno:SetHyperlink with Hyperlink.Text differing from the cell content,
|
||||
// but marked as a hint:
|
||||
uno::Sequence<beans::PropertyValue> aArgs = {
|
||||
comphelper::makePropertyValue(u"Hyperlink.Text"_ustr, uno::Any(u"mytext"_ustr)),
|
||||
comphelper::makePropertyValue(u"Hyperlink.TextIsHint"_ustr, uno::Any(true)),
|
||||
comphelper::makePropertyValue(u"Hyperlink.URL"_ustr,
|
||||
uno::Any(u"http://www.example.com"_ustr)),
|
||||
};
|
||||
dispatchCommand(mxComponent, u".uno:SetHyperlink"_ustr, aArgs);
|
||||
|
||||
// Commit the input mode that InsertURLField left the cell in.
|
||||
ScModule::get()->InputEnterHandler();
|
||||
|
||||
// Then make sure the cell's existing content is preserved as the URL field's
|
||||
// displayed text, not replaced by Hyperlink.Text:
|
||||
const EditTextObject* pEditText = pDoc->GetEditText(ScAddress(0, 0, 0));
|
||||
CPPUNIT_ASSERT(pEditText);
|
||||
const SvxFieldData* pField = pEditText->GetFieldData(0, 0, css::text::textfield::Type::URL);
|
||||
auto pURLField = dynamic_cast<const SvxURLField*>(pField);
|
||||
CPPUNIT_ASSERT(pURLField);
|
||||
// Without the accompanying fix in place, this test would have failed with:
|
||||
// - Expected: foo
|
||||
// - Actual : mytext
|
||||
// i.e. the cell content was lost, the provided text hint was used.
|
||||
CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, pURLField->GetRepresentation());
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -3128,7 +3128,20 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
|
||||
const OUString& rTarget = pHyper->GetTargetFrame();
|
||||
sal_uInt16 nType = static_cast<sal_uInt16>(pHyper->GetInsertMode());
|
||||
|
||||
pTabViewShell->InsertURL( rName, rURL, rTarget, nType );
|
||||
// When the provided text is just a hint, prefer the cell's existing content
|
||||
// over it; if both are missing, use the URL.
|
||||
ScViewData& rData = GetViewData();
|
||||
OUString aCellText = rData.GetDocument().GetString(
|
||||
rData.GetCurX(), rData.GetCurY(), rData.GetTabNumber());
|
||||
OUString sLinkText;
|
||||
if (pHyper->GetTextIsHint() && !aCellText.isEmpty())
|
||||
sLinkText = aCellText;
|
||||
else if (!rName.isEmpty())
|
||||
sLinkText = rName;
|
||||
else
|
||||
sLinkText = rURL;
|
||||
|
||||
pTabViewShell->InsertURL( sLinkText, rURL, rTarget, nType );
|
||||
rReq.Done();
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user