Related: tdf#130370 Let cut&paste/move of a sheet-local name reference ...

... reference the original sheet-local name instead of a same name
on the destination sheet.

In bugdoc https://bugs.documentfoundation.org/attachment.cgi?id=102780
that is the case when cutting Sheet2.B3 and pasting somewhere on Sheet3.
That yielded formula =value with result 3. (after the fix of commit
180fef2a54207555c39fb63ead5e66ba3a71a0cf, before it was #NAME?).
Now it yields the expected formula =Sheet2.value with result 2.

Change-Id: Id92778ea41544583e885eaccfbf82c26762925a5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88939
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx
index a662686..1afe7a3 100644
--- a/sc/source/core/data/document10.cxx
+++ b/sc/source/core/data/document10.cxx
@@ -737,10 +737,13 @@ bool ScDocument::CopyAdjustRangeName( SCTAB& rSheet, sal_uInt16& rIndex, ScRange
        ScDocument& rNewDoc, const ScAddress& rNewPos, const ScAddress& rOldPos, const bool bGlobalNamesToLocal,
        const bool bUsedByFormula ) const
{
    const bool bSameDoc = (rNewDoc.GetPool() == const_cast<ScDocument*>(this)->GetPool());
    if (bSameDoc && ((rSheet < 0 && !bGlobalNamesToLocal) || (rSheet >= 0 && rSheet != rOldPos.Tab())))
    ScDocument* pThis = const_cast<ScDocument*>(this);
    const bool bSameDoc = (rNewDoc.GetPool() == pThis->GetPool());
    if (bSameDoc && ((rSheet < 0 && !bGlobalNamesToLocal) || (rSheet >= 0
                    && (rSheet != rOldPos.Tab() || (IsClipboard() && pThis->IsCutMode())))))
        // Same doc and global name, if not copied to local name, or
        // sheet-local name on other sheet stays the same.
        // sheet-local name on other sheet stays the same. Sheet-local on
        // same sheet also in a clipboard cut&paste / move operation.
        return false;

    // Ensure we don't fiddle with the references until exit.
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 8f9e9a6..a1f6e58 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -3389,15 +3389,6 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnMove(
                            SCTAB nOldTab = (*pp)->GetSheet();
                            if (isNameModified(rCxt.maUpdatedNames, nOldTab, **pp))
                                aRes.mbNameModified = true;
                            if (rCxt.mnTabDelta && aOldRange.In(rOldPos) &&
                                    aOldRange.aStart.Tab() <= nOldTab && nOldTab <= aOldRange.aEnd.Tab())
                            {
                                /* TODO: this may not be needed at all anymore;
                                 * investigate when we actually hit the
                                 * condition. */
                                aRes.mbNameModified = true;
                                (*pp)->SetSheet( nOldTab + rCxt.mnTabDelta);
                            }
                        }
                        break;
                    case ocDBArea: