Skip to content

Commit acd644a

Browse files
committed
[FIX] selection_input: disable spill references
The selection input were replacing classical range strings with spilled references (eg. `A1#`), but those type of ranges are not supported in side panels/charts/pivots/etc.. This commit disable spilled references in selection inputs, we'll see in the future is we want to support them or not. closes #8071 Task: 5945112 X-original-commit: 32709c4 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent aca7925 commit acd644a

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

packages/o-spreadsheet-engine/src/plugins/ui_stateful/selection.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,13 @@ export class GridSelectionPlugin extends UIPlugin {
452452
/**
453453
* Same as `getRangeString` but add:
454454
* - all necessary merge to the range to make it a valid selection
455-
* - the "#" suffix if the range is a spilled reference
455+
* - the "#" suffix if the range is a spilled reference if `allowSpilledReferences` is true
456456
*/
457-
getSelectionRangeString(range: Range, forSheetId: UID): string {
457+
getSelectionRangeString(
458+
range: Range,
459+
forSheetId: UID,
460+
{ allowSpilledReferences } = { allowSpilledReferences: false }
461+
): string {
458462
const expandedZone = this.getters.expandZone(range.sheetId, range.zone);
459463
const expandedRange = createRange(
460464
{
@@ -473,17 +477,20 @@ export class GridSelectionPlugin extends UIPlugin {
473477
return getFullReference(sheetName, xc.split(":")[0]);
474478
}
475479

476-
const spreaderPosition = this.getters.getArrayFormulaSpreadingOn({
477-
sheetId: expandedRange.sheetId,
478-
col: expandedRange.zone.left,
479-
row: expandedRange.zone.top,
480-
});
480+
if (allowSpilledReferences) {
481+
const spreaderPosition = this.getters.getArrayFormulaSpreadingOn({
482+
sheetId: expandedRange.sheetId,
483+
col: expandedRange.zone.left,
484+
row: expandedRange.zone.top,
485+
});
481486

482-
const spreadZone =
483-
spreaderPosition && this.getters.getSpreadZone(spreaderPosition, { ignoreSpillError: true });
484-
if (spreadZone && isEqual(spreadZone, expandedRange.zone)) {
485-
const { sheetName, xc } = splitReference(rangeString);
486-
return getFullReference(sheetName, xc.split(":")[0]) + "#";
487+
const spreadZone =
488+
spreaderPosition &&
489+
this.getters.getSpreadZone(spreaderPosition, { ignoreSpillError: true });
490+
if (spreadZone && isEqual(spreadZone, expandedRange.zone)) {
491+
const { sheetName, xc } = splitReference(rangeString);
492+
return getFullReference(sheetName, xc.split(":")[0]) + "#";
493+
}
487494
}
488495

489496
return rangeString;

src/components/composer/composer/abstract_composer_store.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,17 @@ export abstract class AbstractComposerStore extends SpreadsheetStore {
595595
const inputSheetId = this.sheetId;
596596
const sheetId = this.getters.getActiveSheetId();
597597
const range = this.getters.getRangeFromZone(sheetId, zone);
598-
return this.getters.getSelectionRangeString(range, inputSheetId);
598+
return this.getters.getSelectionRangeString(range, inputSheetId, {
599+
allowSpilledReferences: true,
600+
});
599601
}
600602

601603
private getRangeReference(range: Range, fixedParts: Readonly<RangePart[]>) {
602604
const _fixedParts = [...fixedParts];
603605
const newRange = { ...range, parts: _fixedParts };
604-
return this.getters.getSelectionRangeString(newRange, this.sheetId);
606+
return this.getters.getSelectionRangeString(newRange, this.sheetId, {
607+
allowSpilledReferences: true,
608+
});
605609
}
606610

607611
/**

tests/selection_input/selection_input_store.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ describe("selection input plugin", () => {
9292
expect(highlightedZones(container)).toStrictEqual(["A2:A4"]);
9393
});
9494

95+
test("selecting the range of a spilled formula does not create a spill reference", () => {
96+
const { store, model } = makeStore(SelectionInputStore);
97+
setCellContent(model, "A1", "=MUNIT(2)");
98+
store.focusById(idOfRange(store, 0));
99+
setSelection(model, ["A1:B2"]);
100+
expect(store.selectionInputs[0].xc).not.toBe("A1#");
101+
expect(store.selectionInputs[0].xc).toBe("A1:B2");
102+
});
103+
95104
test("focus input which is already focused", () => {
96105
const { store } = makeStore(SelectionInputStore);
97106
store.focusById(idOfRange(store, 0));

0 commit comments

Comments
 (0)