sc/inc/rangeutl.hxx | 3 ++- sc/source/core/tool/rangeutl.cxx | 16 ++++++++++++---- sc/source/ui/view/tabvwsh3.cxx | 6 +++--- 3 files changed, 17 insertions(+), 8 deletions(-)
New commits: commit b3fee70c26c139a4b301e5465be63e17554fa573 Author: Eike Rathke <er...@redhat.com> AuthorDate: Tue Oct 12 13:56:09 2021 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Oct 13 15:57:16 2021 +0200 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 <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit 57f09e6f3cfdd9ad4e1673df14e6ee550d402743) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123507 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/inc/rangeutl.hxx b/sc/inc/rangeutl.hxx index 2f4a988725be..33f531444280 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 a80db03c56f1..3e5a609e9af1 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 7bbbd9647a4e..af7e31da4d98 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 )