sc/source/ui/view/tabcont.cxx  |    8 +++++++-
 sc/source/ui/view/tabvwshf.cxx |   12 ++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

New commits:
commit 373e102b2eaf62c272dde3c9717b5dca7906b721
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Mar 8 17:50:01 2026 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Mar 8 18:47:41 2026 +0100

    tdf#171174: also correct target index for Move/Copy Sheet dialog
    
    See also: I13504468119706597ca25c14309e6548ea4ca588.
    
    Change-Id: I7fe2e58b78d808a195b0ad45fc8e132993ea04f9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201210
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index fe196f52599a..761f28e7e09c 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -215,7 +215,6 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                 SCTAB nTab = rViewData.CurrentTabForData();
                 OUString aDocName = 
GetViewData().GetDocShell()->GetTitle(SFX_TITLE_FULLNAME);
                 sal_uInt16 nDoc = 0;
-                bool bCpy = true;
 
                 SfxObjectShell* pSh = SfxObjectShell::GetFirst();
                 ScDocShell* pScSh = nullptr;
@@ -239,7 +238,7 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                     pSh = SfxObjectShell::GetNext( *pSh );
                 }
 
-                MoveTable( nDoc, nTab + 1, bCpy );
+                MoveTable(nDoc, nTab + 1, true);
             }
             break;
 
@@ -994,6 +993,15 @@ void ScTabViewShell::DoMoveTableFromDialog( SfxRequest& 
rReq, const VclPtr<Abstr
     sal_uInt16 nDoc = pDlg->GetSelectedDocument();
     SCTAB nTab = pDlg->GetSelectedTable();
     bool bCpy = pDlg->GetCopyTable();
+    if (!bCpy)
+    {
+        SCTAB nOldIndex = GetViewData().GetMarkData().GetFirstSelected();
+        if (nTab > nOldIndex)
+        {
+            // move right: target index will be one less after source tab is 
removed
+            --nTab;
+        }
+    }
     bool bRna = pDlg->GetRenameTable();
     OUString aTabName;
     // Leave aTabName string empty, when Rename is FALSE.
commit 5eeba2e25fa6fbb5bcc714aa74cdc055d433e864
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Mar 8 16:30:09 2026 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sun Mar 8 18:47:31 2026 +0100

    tdf#171174: the target position is one less when moving to the right
    
    Change-Id: I13504468119706597ca25c14309e6548ea4ca588
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201207
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sc/source/ui/view/tabcont.cxx b/sc/source/ui/view/tabcont.cxx
index cdb77fd4645b..c200f43959cf 100644
--- a/sc/source/ui/view/tabcont.cxx
+++ b/sc/source/ui/view/tabcont.cxx
@@ -551,7 +551,13 @@ sal_Int8 ScTabControl::ExecuteDrop( const 
ExecuteDropEvent& rEvt )
         SCTAB nPos = GetPrivatDropPos( rEvt.maPosPixel );
         HideDropPos();
 
-        if ( nPos == pData->pCellTransfer->GetVisibleTab() && rEvt.mnAction == 
DND_ACTION_MOVE )
+        SCTAB nOldPos = pData->pCellTransfer->GetVisibleTab();
+        if (rEvt.mnAction == DND_ACTION_MOVE && nPos > nOldPos)
+        {
+            // when moving to the right, the position is one less after 
removing the table
+            --nPos;
+        }
+        if (nPos == nOldPos && rEvt.mnAction == DND_ACTION_MOVE)
         {
             // #i83005# do nothing - don't move to the same position
             // (too easily triggered unintentionally, and might take a long 
time in large documents)

Reply via email to