summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-10-27 07:32:32 -0700
committerEike Rathke <erack@redhat.com>2014-11-04 15:43:58 +0000
commitbc38612d349b9efd877dec23f3e68a3f7b945cec (patch)
treee33bf0112fa273ce70334d216b89bb9d158333ec
parentdb8cc3a1c481bd1f97b2688ff85a00eec8b25926 (diff)
fdo#85282: Correct adjustment of range reference on delete & shift.
Change-Id: I6e01c160f77599dfa4a2e55b60e23d256184c822 (cherry picked from commit c3c16d5b74fb5707691283538a969a03c2f918b0) Reviewed-on: https://gerrit.libreoffice.org/12111 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/source/core/tool/token.cxx67
1 files changed, 61 insertions, 6 deletions
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 84c8ccc40d57..b0a495afe3d2 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -2546,6 +2546,9 @@ void setRefDeleted( ScComplexRefData& rRef, const sc::RefUpdateContext& rCxt )
bool shrinkRange( const sc::RefUpdateContext& rCxt, ScRange& rRefRange, const ScRange& rDeletedRange )
{
+ if (!rDeletedRange.Intersects(rRefRange))
+ return false;
+
if (rCxt.mnColDelta < 0)
{
// Shifting left.
@@ -2553,9 +2556,35 @@ bool shrinkRange( const sc::RefUpdateContext& rCxt, ScRange& rRefRange, const Sc
// Deleted range is only partially overlapping in vertical direction. Bail out.
return false;
- // Move the last column position to the left.
- SCCOL nDelta = rDeletedRange.aStart.Col() - rDeletedRange.aEnd.Col() - 1;
- rRefRange.aEnd.IncCol(nDelta);
+ if (rDeletedRange.aStart.Col() <= rRefRange.aStart.Col())
+ {
+ if (rRefRange.aEnd.Col() <= rDeletedRange.aEnd.Col())
+ {
+ // Reference is entirely deleted.
+ rRefRange.SetInvalid();
+ }
+ else
+ {
+ // The reference range is truncated on the left.
+ SCCOL nOffset = rDeletedRange.aStart.Col() - rRefRange.aStart.Col();
+ SCCOL nDelta = rRefRange.aStart.Col() - rDeletedRange.aEnd.Col() - 1;
+ rRefRange.aStart.IncCol(nOffset);
+ rRefRange.aEnd.IncCol(nDelta+nOffset);
+ }
+ }
+ else if (rDeletedRange.aEnd.Col() < rRefRange.aEnd.Col())
+ {
+ // Reference is deleted in the middle. Move the last column
+ // position to the left.
+ SCCOL nDelta = rDeletedRange.aStart.Col() - rDeletedRange.aEnd.Col() - 1;
+ rRefRange.aEnd.IncCol(nDelta);
+ }
+ else
+ {
+ // The reference range is truncated on the right.
+ SCCOL nDelta = rDeletedRange.aStart.Col() - rRefRange.aEnd.Col() - 1;
+ rRefRange.aEnd.IncCol(nDelta);
+ }
return true;
}
else if (rCxt.mnRowDelta < 0)
@@ -2566,9 +2595,35 @@ bool shrinkRange( const sc::RefUpdateContext& rCxt, ScRange& rRefRange, const Sc
// Deleted range is only partially overlapping in horizontal direction. Bail out.
return false;
- // Move the last row position up.
- SCROW nDelta = rDeletedRange.aStart.Row() - rDeletedRange.aEnd.Row() - 1;
- rRefRange.aEnd.IncRow(nDelta);
+ if (rDeletedRange.aStart.Row() <= rRefRange.aStart.Row())
+ {
+ if (rRefRange.aEnd.Row() <= rDeletedRange.aEnd.Row())
+ {
+ // Reference is entirely deleted.
+ rRefRange.SetInvalid();
+ }
+ else
+ {
+ // The reference range is truncated on the top.
+ SCCOL nOffset = rDeletedRange.aStart.Row() - rRefRange.aStart.Row();
+ SCCOL nDelta = rRefRange.aStart.Row() - rDeletedRange.aEnd.Row() - 1;
+ rRefRange.aStart.IncRow(nOffset);
+ rRefRange.aEnd.IncRow(nDelta+nOffset);
+ }
+ }
+ else if (rDeletedRange.aEnd.Row() < rRefRange.aEnd.Row())
+ {
+ // Reference is deleted in the middle. Move the last row
+ // position upward.
+ SCCOL nDelta = rDeletedRange.aStart.Row() - rDeletedRange.aEnd.Row() - 1;
+ rRefRange.aEnd.IncRow(nDelta);
+ }
+ else
+ {
+ // The reference range is truncated on the bottom.
+ SCCOL nDelta = rDeletedRange.aStart.Row() - rRefRange.aEnd.Row() - 1;
+ rRefRange.aEnd.IncRow(nDelta);
+ }
return true;
}