Resolves: tdf#145077 Use position for jumping to named relative references
For named ranges with relative references construct the resulting
cell range reference to be selected according to the current cell
cursor position, same as in Manage Names and as they would result
if used in a formula expression on that position.
Change-Id: I8362c3e38086337ad90aa84cc7c13f284b41d9fc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123450
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sc/inc/rangeutl.hxx b/sc/inc/rangeutl.hxx
index 2f4a9887..33f5314 100644
--- a/sc/inc/rangeutl.hxx
+++ b/sc/inc/rangeutl.hxx
@@ -82,7 +82,8 @@ public:
SCTAB nCurTab,
ScRange& rRange,
RutlNameScope eScope=RUTL_NAMES,
ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 );
ScAddress::Details const & rDetails = ScAddress::detailsOOOa1,
bool bUseDetailsPos = false );
};
class SC_DLLPUBLIC ScRangeStringConverter
diff --git a/sc/source/core/tool/rangeutl.cxx b/sc/source/core/tool/rangeutl.cxx
index 34541e5..fd660a8 100644
--- a/sc/source/core/tool/rangeutl.cxx
+++ b/sc/source/core/tool/rangeutl.cxx
@@ -236,7 +236,8 @@ bool ScRangeUtil::MakeRangeFromName (
SCTAB nCurTab,
ScRange& rRange,
RutlNameScope eScope,
ScAddress::Details const & rDetails )
ScAddress::Details const & rDetails,
bool bUseDetailsPos )
{
bool bResult = false;
if (rName.isEmpty())
@@ -292,9 +293,16 @@ bool ScRangeUtil::MakeRangeFromName (
ScRefAddress aStartPos;
ScRefAddress aEndPos;
// tdf#138646 - consider the current grammar and address convention of the document
pData->GetSymbol(aStrArea,
FormulaGrammar::mergeToGrammar(rDoc.GetGrammar(), rDetails.eConv));
// tdf#138646: use the current grammar of the document and passed
// address convention.
// tdf#145077: create range string according to current cell cursor
// position if expression has relative references and details say so.
if (bUseDetailsPos)
pData->GetSymbol( aStrArea, ScAddress( rDetails.nCol, rDetails.nRow, nCurTab),
FormulaGrammar::mergeToGrammar(rDoc.GetGrammar(), rDetails.eConv));
else
pData->GetSymbol( aStrArea,
FormulaGrammar::mergeToGrammar(rDoc.GetGrammar(), rDetails.eConv));
if ( IsAbsArea( aStrArea, rDoc, nTable,
nullptr, &aStartPos, &aEndPos, rDetails ) )
diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx
index 03e8dd4..2fa44e4 100644
--- a/sc/source/ui/view/tabvwsh3.cxx
+++ b/sc/source/ui/view/tabvwsh3.cxx
@@ -374,9 +374,9 @@ void ScTabViewShell::Execute( SfxRequest& rReq )
else
{
const RutlNameScope eScope = (bForceGlobalName ? RUTL_NAMES_GLOBAL : RUTL_NAMES);
formula::FormulaGrammar::AddressConvention eConv = rDoc.GetAddressConvention();
if( ScRangeUtil::MakeRangeFromName( aAddress, rDoc, nTab, aScRange, eScope, eConv ) ||
ScRangeUtil::MakeRangeFromName( aAddress, rDoc, nTab, aScRange, RUTL_DBASE, eConv ) )
ScAddress::Details aDetails( rDoc.GetAddressConvention(), rViewData.GetCurY(), rViewData.GetCurX());
if (ScRangeUtil::MakeRangeFromName( aAddress, rDoc, nTab, aScRange, eScope, aDetails, true) ||
ScRangeUtil::MakeRangeFromName( aAddress, rDoc, nTab, aScRange, RUTL_DBASE, aDetails, true))
{
nResult |= ScRefFlags::VALID;
if( aScRange.aStart.Tab() != nTab )