Skip to content

Commit

Permalink
[FIX] SheetPlugin: Fix handling of unbounded zones
Browse files Browse the repository at this point in the history
The getter `getUnboundedZone` did not properly support unbounded zones
as arguments.

closes #5338

Task: 4397745
Signed-off-by: Vincent Schippefilt (vsc) <[email protected]>
  • Loading branch information
rrahir authored and VincentSchippefilt committed Dec 12, 2024
1 parent 5be7697 commit 8ac3b3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/plugins/core/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ export class SheetPlugin extends CorePlugin<SheetState> implements SheetState {
}

getUnboundedZone(sheetId: UID, zone: Zone | UnboundedZone): UnboundedZone {
if (zone.bottom === undefined || zone.right === undefined) {
return zone;
}
const isFullRow = zone.left === 0 && zone.right === this.getNumberCols(sheetId) - 1;
const isFullCol = zone.top === 0 && zone.bottom === this.getNumberRows(sheetId) - 1;
return {
Expand Down
12 changes: 11 additions & 1 deletion tests/sheet/sheets_plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FORBIDDEN_SHEETNAME_CHARS } from "../../src/constants";
import { getCanonicalSheetName, numberToLetters, toZone } from "../../src/helpers";
import { getCanonicalSheetName, numberToLetters, toUnboundedZone, toZone } from "../../src/helpers";
import { Model } from "../../src/model";
import { CommandResult } from "../../src/types";
import {
Expand Down Expand Up @@ -1075,4 +1075,14 @@ describe("sheets", () => {
const zone = toZone("A1:J1");
expect(model.getters.getUnboundedZone(sheetId, zone)).toEqual({ ...zone, right: undefined });
});

test.each<string>(["A1:Z", "A2:Z", "B2:26", "B1:26", "A:A", "A:A3"])(
"GetUnboundedZone : Unbounded range '%s' is unaffected",
(xc) => {
const model = new Model();
const sheetId = model.getters.getActiveSheetId();
const zone = toUnboundedZone(xc);
expect(model.getters.getUnboundedZone(sheetId, zone)).toEqual(zone);
}
);
});

0 comments on commit 8ac3b3c

Please sign in to comment.