From a6634031e3bbff041c9d48e61b150b2ddab069ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir=20=28rar=29?= Date: Mon, 18 Nov 2024 13:12:14 +0100 Subject: [PATCH] [FIX] Evaluation: Remove old spreaded cells from spread relations 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). Task: 4342240 --- .../ui_core_views/cell_evaluation/evaluator.ts | 1 + .../evaluation/evaluation_formula_array.test.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/plugins/ui_core_views/cell_evaluation/evaluator.ts b/src/plugins/ui_core_views/cell_evaluation/evaluator.ts index bfadd39bcf..80471f5644 100644 --- a/src/plugins/ui_core_views/cell_evaluation/evaluator.ts +++ b/src/plugins/ui_core_views/cell_evaluation/evaluator.ts @@ -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); } diff --git a/tests/evaluation/evaluation_formula_array.test.ts b/tests/evaluation/evaluation_formula_array.test.ts index 01f6966ab2..8e1df664e9 100644 --- a/tests/evaluation/evaluation_formula_array.test.ts +++ b/tests/evaluation/evaluation_formula_array.test.ts @@ -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, @@ -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)");