Skip to content

Commit

Permalink
Add morph and translate methods to CellRange
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Kirschner committed Sep 28, 2020
1 parent d39cea0 commit f835895
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/core/cell_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f835895

Please sign in to comment.