From bddbe4b8eed870300403ae31c94a87339934ab4d Mon Sep 17 00:00:00 2001 From: Jared Kirschner Date: Wed, 9 Sep 2020 19:18:40 -0400 Subject: [PATCH] Add morph and translate methods to CellRange --- src/core/cell_range.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/core/cell_range.js b/src/core/cell_range.js index b8e3730b..d50d4a1c 100644 --- a/src/core/cell_range.js +++ b/src/core/cell_range.js @@ -208,14 +208,24 @@ class CellRange { // Translates the cell range by the given values, unless such a translation // would be invalid (e.g., index less than 1) translate(rowShift, colShift) { + // Morph the same amount in each direction, resulting in a translation + this.morph(colShift, rowShift, colShift, rowShift); + } + + // Move the left, top, right, and bottom boundaries of the cell range by the + // specified amounts + morph(leftShift, topShift, rightShift, bottomShift) { + // Start is left/top. + // End is bottom/right. + // Ensure row/col values remain valid (>= 0) // NOTE: this assumes a cellRange isn't used with a row or column index of // -1, which is sometimes used in the application to denote an entire row // or column is being referenced (not just a single index) - this.sri = Math.max(0, this.sri + rowShift); - this.eri = Math.max(0, this.eri + rowShift); - this.sci = Math.max(0, this.sci + colShift); - this.eci = Math.max(0, this.eci + colShift); + this.sri = Math.max(0, this.sri + topShift); + this.eri = Math.max(0, this.eri + bottomShift); + this.sci = Math.max(0, this.sci + leftShift); + this.eci = Math.max(0, this.eci + rightShift); } static valueOf(ref) {