diff options
author | Gökay Şatır <gokaysatir@collabora.com> | 2023-10-30 12:37:23 +0300 |
---|---|---|
committer | Gökay ŞATIR <gokaysatir@collabora.com> | 2024-05-10 08:02:47 +0200 |
commit | a578321434ada456be3fc7a91b3da9321ce01c5a (patch) | |
tree | 9e93623e48328fb8fae66590870c3d78023bbee6 /sc/source/ui | |
parent | aa836383900a468a3d50abe534de028e47e343fd (diff) |
Fix row deletion bug.
When multiple users are editing a Calc document:
* If one user selects a whole row and another one deletes a range of rows including or above the selected row, app crashes.
* This PR fixes the crash.
* Also when multiple rows are deleted, other user's selected row is moved only one row. This PR moves the selected row according to the deleted row count.
* The cursor position was also causing a crash, fixed.
Signed-off-by: Gökay Şatır <gokaysatir@collabora.com>
Change-Id: Ie4b893fee7192492efacbb167b747434336384e3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158650
Reviewed-by: Marco Cecchetti <marco.cecchetti@collabora.com>
Tested-by: Marco Cecchetti <marco.cecchetti@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167373
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/view/viewfunc.cxx | 14 |
2 files changed, 12 insertions, 6 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index aa8a5d64d7fe..c33daee69b14 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -2280,7 +2280,7 @@ bool ScDocFunc::InsertCells( const ScRange& rRange, const ScMarkData* pTabMark, if (bInsertRows) { - pViewSh->OnLOKInsertDeleteRow(rRange.aStart.Row(), 1); + pViewSh->OnLOKInsertDeleteRow(rRange.aStart.Row() - (eCmd == INS_INSROWS_BEFORE ? 1: 0), 1); } } @@ -2860,7 +2860,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark, } if (eCmd == DelCellCmd::Rows) { - pViewSh->OnLOKInsertDeleteRow(rRange.aStart.Row(), -1); + pViewSh->OnLOKInsertDeleteRow(rRange.aStart.Row(), -1 * (rRange.aEnd.Row() - rRange.aStart.Row() + 1)); } } diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index 8d77023cbaa9..db2bb7c8e717 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -1779,11 +1779,17 @@ void ScViewFunc::OnLOKInsertDeleteRow(SCROW nStartRow, tools::Long nOffset) if (pTabViewShell->getPart() == nCurrentTabIndex) { SCROW nY = pTabViewShell->GetViewData().GetCurY(); - if (nY > nStartRow || (nY == nStartRow && nOffset > 0)) + if (nY > nStartRow) { + tools::Long offset = nOffset; + if (nOffset + nStartRow > nY) + offset = nY - nStartRow; + else if (nOffset < 0 && nStartRow - nOffset > nY) + offset = -1 * (nY - nStartRow); + ScInputHandler* pInputHdl = pTabViewShell->GetInputHandler(); SCCOL nX = pTabViewShell->GetViewData().GetCurX(); - pTabViewShell->SetCursor(nX, nY + nOffset); + pTabViewShell->SetCursor(nX, nY + offset); if (pInputHdl && pInputHdl->IsInputMode()) { pInputHdl->SetModified(); @@ -1792,8 +1798,8 @@ void ScViewFunc::OnLOKInsertDeleteRow(SCROW nStartRow, tools::Long nOffset) ScMarkData aMultiMark( pTabViewShell->GetViewData().GetMarkData() ); aMultiMark.SetMarking( false ); - aMultiMark.MarkToMulti(); - if (aMultiMark.IsMultiMarked()) + + if (aMultiMark.IsMultiMarked() || aMultiMark.IsMarked()) { aMultiMark.ShiftRows(pTabViewShell->GetViewData().GetDocument(), nStartRow, nOffset); pTabViewShell->SetMarkData(aMultiMark); |