sc/source/core/tool/refupdat.cxx |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

New commits:
commit c0b46a8270507dc59b731e9c996960374b0db472
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Tue Dec 5 20:58:49 2023 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Dec 6 09:27:36 2023 +0100

    Resolves: tdf#158223 Revert "fix" for tdf#156174 and follow-up
    
    ... introducing a real fix.
    
        commit 94ca402cd1fe2fd9776d08448f7216b7f638e69a
        CommitDate: Tue Jul 25 15:04:01 2023 +0200
    
            tdf#156174 sc DBData: fix regression of database ranges
    
    just cured a symptom by removing a condition that shouldn't had been
    removed, instead of getting to the real cause of an odd reference
    update.
    
    Shrinking the end of a sheet reference range and thus moving it one
    before the previously referenced relative position is only possible if
    the deleted sheet actually touches the referenced range, which here the
    start value points to and thus checking ref>=start+delta is not
    necessary and subtracting 1 even harms. This is different from deleting
    columns or rows where the start value points behind the deleted area of
    moving the following area.
    
    Change-Id: If9ae5dd6f6ae5cd248ad5d999f1aa7577d4ec035
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160374
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit ec165d6fe3784f5cd78351a537abf69e88b68420)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160354
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/source/core/tool/refupdat.cxx b/sc/source/core/tool/refupdat.cxx
index e05a14d0137f..95f738c4ed84 100644
--- a/sc/source/core/tool/refupdat.cxx
+++ b/sc/source/core/tool/refupdat.cxx
@@ -25,12 +25,12 @@
 #include <osl/diagnose.h>
 
 template< typename R, typename S, typename U >
-static bool lcl_MoveStart( R& rRef, U nStart, S nDelta, U nMask )
+static bool lcl_MoveStart( R& rRef, U nStart, S nDelta, U nMask, bool bShrink 
= true )
 {
     bool bCut = false;
     if ( rRef >= nStart )
         rRef = sal::static_int_cast<R>( rRef + nDelta );
-    else if ( nDelta < 0 && rRef >= nStart + nDelta )
+    else if ( nDelta < 0 && bShrink && rRef >= nStart + nDelta )
         rRef = nStart + nDelta;             //TODO: limit ???
     if ( rRef < 0 )
     {
@@ -46,12 +46,12 @@ static bool lcl_MoveStart( R& rRef, U nStart, S nDelta, U 
nMask )
 }
 
 template< typename R, typename S, typename U >
-static bool lcl_MoveEnd( R& rRef, U nStart, S nDelta, U nMask )
+static bool lcl_MoveEnd( R& rRef, U nStart, S nDelta, U nMask, bool bShrink = 
true )
 {
     bool bCut = false;
     if ( rRef >= nStart )
         rRef = sal::static_int_cast<R>( rRef + nDelta );
-    else if ( nDelta < 0 && rRef >= nStart + nDelta )
+    else if ( nDelta < 0 && bShrink && rRef >= nStart + nDelta )
         rRef = nStart + nDelta - 1;         //TODO: limit ???
     if (rRef < 0)
     {
@@ -284,9 +284,14 @@ ScRefUpdateRes ScRefUpdate::Update( const ScDocument* 
pDoc, UpdateRefMode eUpdat
             SCTAB nMaxTab = pDoc->GetTableCount() - 1;
             nMaxTab = sal::static_int_cast<SCTAB>(nMaxTab + nDz);      // 
adjust to new count
             bool bExp = (bExpand && IsExpand( theTab1, theTab2, nTab1, nDz ));
-            bCut1 = lcl_MoveStart( theTab1, nTab1, nDz, nMaxTab );
-            bCut2 = lcl_MoveEnd( theTab2, nTab1, nDz, nMaxTab );
-            if ( bCut1 || bCut2 )
+            bCut1 = lcl_MoveStart( theTab1, nTab1, nDz, nMaxTab, false 
/*bShrink*/);
+            bCut2 = lcl_MoveEnd( theTab2, nTab1, nDz, nMaxTab, false 
/*bShrink*/);
+            if ( theTab2 < theTab1 )
+            {
+                eRet = UR_INVALID;
+                theTab2 = theTab1;
+            }
+            else if ( bCut1 || bCut2 )
                 eRet = UR_UPDATED;
             if ( bExp )
             {

Reply via email to