Skip to content

Commit

Permalink
[FIX] Evaluation: Remove old spreaded cells from spread relations
Browse files Browse the repository at this point in the history
Currently, the spread relations of a spreaded formula are not invalidated.
The evaluated value of the relation is currently properly invalidated
so it's not posing any problem during the evaluation/display
phase but some features rely specifically on the spreading relation
(e.g. the pivot cells highlighting in the top bar) and the current
situation leads to false positives (see attached test).

closes #5225

Task: 4342240
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
rrahir committed Nov 26, 2024
1 parent 23f8fc3 commit a6f7d40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugins/ui_core_views/cell_evaluation/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ export class Evaluator {
this.evaluatedCells.delete(child);
this.nextPositionsToUpdate.addMany(this.getCellsDependingOn([child]));
this.nextPositionsToUpdate.addMany(this.getArrayFormulasBlockedBy(child));
this.spreadingRelations.removeNode(child);
}
this.spreadingRelations.removeNode(positionId);
}
Expand Down
16 changes: 16 additions & 0 deletions tests/evaluation/evaluation_formula_array.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { arg, functionRegistry } from "../../src/functions";
import { toNumber } from "../../src/functions/helpers";
import { toCartesian } from "../../src/helpers";
import { Model } from "../../src/model";
import {
Arg,
Expand Down Expand Up @@ -747,6 +748,21 @@ describe("evaluate formulas that return an array", () => {
expect(c).toEqual(2);
});

test("Cells that no longer depend on the array formula are removed from the spreading dependencies", () => {
setCellContent(model, "A1", "=TRANSPOSE(A3:A4)");
setCellContent(model, "A3", "3");
setCellContent(model, "A4", "4");
expect(getEvaluatedCell(model, "B1").value).toEqual(4);
const sheetId = model.getters.getActiveSheetId();
expect(model.getters.getCorrespondingFormulaCell({ sheetId, ...toCartesian("B1") })).toBe(
model.getters.getCorrespondingFormulaCell({ sheetId, ...toCartesian("A1") })
);
setCellContent(model, "A1", "=TRANSPOSE(A3)");
expect(
model.getters.getCorrespondingFormulaCell({ sheetId, ...toCartesian("B1") })
).toBeUndefined();
});

test("have collision when spread size zone change", () => {
setCellContent(model, "A1", "1");
setCellContent(model, "B1", "=MFILL(1,A1+1,42)");
Expand Down

0 comments on commit a6f7d40

Please sign in to comment.