diff options
author | u9g <git@u9g.dev> | 2022-03-04 01:46:58 +0000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-03-05 05:46:35 +0330 |
commit | 87c818c571c6a3bf3e653b06dba0b0eca4e86284 (patch) | |
tree | ba2028516039c9b78ffce2d4267e791cfcdef9e2 /Base/res | |
parent | 7d052250f24b6419e1c3297f2b6a10c71fc2b6e9 (diff) | |
download | serenity-87c818c571c6a3bf3e653b06dba0b0eca4e86284.zip |
Spreadsheet: Put common Range(s) functionality into CommonRange class
Diffstat (limited to 'Base/res')
-rw-r--r-- | Base/res/js/Spreadsheet/runtime.js | 62 |
1 files changed, 24 insertions, 38 deletions
diff --git a/Base/res/js/Spreadsheet/runtime.js b/Base/res/js/Spreadsheet/runtime.js index 5bff2f269b..daed33169d 100644 --- a/Base/res/js/Spreadsheet/runtime.js +++ b/Base/res/js/Spreadsheet/runtime.js @@ -128,8 +128,29 @@ class Position { } } -class Ranges { +class CommonRange { + at(wantedIx) { + let ix = 0; + let found = null; + this.forEach(cell => { + if (ix++ === wantedIx) { + found = cell; + return Break; + } + }); + return found; + } + + toArray() { + const cells = []; + this.forEach(val => cells.push(val)); + return cells; + } +} + +class Ranges extends CommonRange { constructor(ranges) { + super(); this.ranges = ranges; } @@ -147,18 +168,6 @@ class Ranges { } } - at(wantedIx) { - let ix = 0; - let found = null; - this.forEach(cell => { - if (ix++ === wantedIx) { - found = cell; - return Break; - } - }); - return found; - } - union(other, direction = "right") { if (direction === "left") { if (other instanceof Ranges) return Ranges.from(...other.ranges, ...this.ranges); @@ -171,19 +180,14 @@ class Ranges { } } - toArray() { - const cells = []; - this.forEach(val => cells.push(val)); - return cells; - } - toString() { return `Ranges.from(${this.ranges.map(r => r.toString()).join(", ")})`; } } -class Range { +class Range extends CommonRange { constructor(startingColumnName, endingColumnName, startingRow, endingRow, columnStep, rowStep) { + super(); // using == to account for '0' since js will parse `+'0'` to 0 if (columnStep == 0 || rowStep == 0) throw new Error("rowStep or columnStep is 0, this will cause an infinite loop"); @@ -235,18 +239,6 @@ class Range { } } - at(wantedIx) { - let ix = 0; - let found = null; - this.forEach(cell => { - if (ix++ === wantedIx) { - found = cell; - return Break; - } - }); - return found; - } - union(other) { if (other instanceof Ranges) return other.union(this, "left"); @@ -273,12 +265,6 @@ class Range { } } - toArray() { - const cells = []; - this.forEach(val => cells.push(val)); - return cells; - } - toString() { const endingRow = this.endingRow ?? ""; const showSteps = this.rowStep !== 1 || this.columnStep !== 1; |