mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
Spreadsheet: Add Range(s).at(ix)
This commit is contained in:
parent
629eed3a4c
commit
d047f26a74
2 changed files with 37 additions and 0 deletions
|
@ -147,6 +147,18 @@ 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") {
|
union(other, direction = "right") {
|
||||||
if (direction === "left") {
|
if (direction === "left") {
|
||||||
if (other instanceof Ranges) return Ranges.from(...other.ranges, ...this.ranges);
|
if (other instanceof Ranges) return Ranges.from(...other.ranges, ...this.ranges);
|
||||||
|
@ -213,6 +225,18 @@ class Range {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
at(wantedIx) {
|
||||||
|
let ix = 0;
|
||||||
|
let found = null;
|
||||||
|
this.forEach(cell => {
|
||||||
|
if (ix++ === wantedIx) {
|
||||||
|
found = cell;
|
||||||
|
return Break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
union(other) {
|
union(other) {
|
||||||
if (other instanceof Ranges) return other.union(this, "left");
|
if (other instanceof Ranges) return other.union(this, "left");
|
||||||
|
|
||||||
|
|
|
@ -108,4 +108,17 @@ describe("Range", () => {
|
||||||
expect(R`A0:A25`.first().name).toEqual("A0");
|
expect(R`A0:A25`.first().name).toEqual("A0");
|
||||||
expect(R`A2:A25`.first().name).toEqual("A2");
|
expect(R`A2:A25`.first().name).toEqual("A2");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Range#at", () => {
|
||||||
|
const workbook = createWorkbook();
|
||||||
|
const sheet = createSheet(workbook, "Sheet 1");
|
||||||
|
sheet.makeCurrent();
|
||||||
|
let i = 0;
|
||||||
|
for (const col of ["A", "B"])
|
||||||
|
for (const row of [0, 1, 2]) sheet.setCell(col, row, Math.pow(i++, 2));
|
||||||
|
|
||||||
|
sheet.focusCell("A", 0);
|
||||||
|
expect(R`A0:A2`.at(2)).toEqual("A2");
|
||||||
|
expect(Ranges.from(R`A0:A2`, R`B0:B2`).at(5)).toEqual("B2");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue