diff options
author | Gökay Şatır <gokaysatir@collabora.com> | 2023-10-26 14:48:49 +0300 |
---|---|---|
committer | Gökay ŞATIR <gokaysatir@collabora.com> | 2024-05-10 08:07:04 +0200 |
commit | 61ada4483c50d78387ff0ac45a97f2ee5b328029 (patch) | |
tree | ffd9fb1d713f56f45e3eb854dc38a21093188a08 /sc/source/ui | |
parent | 69980bb2f951f780e63718215ca522a69676febf (diff) |
Fix column deletion bug.
When multiple users are editing a Calc document:
* If one user selects a whole column and another one deletes a range of columns including or on the left of the selected column, app crashes.
* This PR fixes the crash.
* Also when multiple columns are deleted, other user's selected column is moved only one column to the left. This PR moves the selected column to the left according to the deleted column count.
* The cursor position was also causing a crash, fixed.
Signed-off-by: Gökay Şatır <gokaysatir@collabora.com>
Change-Id: Ib00488f387a91aa0109bcc30feacad52e1b14a30
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158503
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167220
Tested-by: Jenkins
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 430fbe53ddd3..55f9c209f599 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -2275,7 +2275,7 @@ bool ScDocFunc::InsertCells( const ScRange& rRange, const ScMarkData* pTabMark, if (bInsertCols) { - pViewSh->OnLOKInsertDeleteColumn(rRange.aStart.Col(), 1); + pViewSh->OnLOKInsertDeleteColumn(rRange.aStart.Col() - (eCmd == INS_INSCOLS_BEFORE ? 1: 0), 1); } if (bInsertRows) @@ -2856,7 +2856,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark, { if (eCmd == DelCellCmd::Cols) { - pViewSh->OnLOKInsertDeleteColumn(rRange.aStart.Col(), -1); + pViewSh->OnLOKInsertDeleteColumn(rRange.aStart.Col(), -1 * (rRange.aEnd.Col() - rRange.aStart.Col() + 1)); } if (eCmd == DelCellCmd::Rows) { diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index d6cf4b13ca01..d0945c76febc 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -1713,11 +1713,17 @@ void ScViewFunc::OnLOKInsertDeleteColumn(SCCOL nStartCol, tools::Long nOffset) if (pTabViewShell->getPart() == nCurrentTabIndex) { SCCOL nX = pTabViewShell->GetViewData().GetCurX(); - if (nX > nStartCol || (nX == nStartCol && nOffset > 0)) + if (nX > nStartCol) { + tools::Long offset = nOffset; + if (nOffset + nStartCol > nX) + offset = nX - nStartCol; + else if (nOffset < 0 && nStartCol - nOffset > nX) + offset = -1 * (nX - nStartCol); + ScInputHandler* pInputHdl = pTabViewShell->GetInputHandler(); SCROW nY = pTabViewShell->GetViewData().GetCurY(); - pTabViewShell->SetCursor(nX + nOffset, nY); + pTabViewShell->SetCursor(nX + offset, nY); if (pInputHdl && pInputHdl->IsInputMode()) { pInputHdl->SetModified(); @@ -1726,8 +1732,8 @@ void ScViewFunc::OnLOKInsertDeleteColumn(SCCOL nStartCol, tools::Long nOffset) ScMarkData aMultiMark( pTabViewShell->GetViewData().GetMarkData() ); aMultiMark.SetMarking( false ); - aMultiMark.MarkToMulti(); - if (aMultiMark.IsMultiMarked()) + + if (aMultiMark.IsMultiMarked() || aMultiMark.IsMarked()) { aMultiMark.ShiftCols(pTabViewShell->GetViewData().GetDocument(), nStartCol, nOffset); pTabViewShell->SetMarkData(aMultiMark); |