From 35ca29c014828c5c1fcf0dc81da5a87022d88720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir=20=28rar=29?= Date: Mon, 18 Nov 2024 12:12:14 +0000 Subject: [PATCH] [FIX] Evaluation: Remove old spreaded cells from spread relations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 odoo/o-spreadsheet#5275 Task: 4342240 X-original-commit: 8d4accfa0f6bcfe966d28af0b8a1c65399f8809e Signed-off-by: Lucas Lefèvre (lul) Signed-off-by: Rémi Rahir (rar) --- .../evaluation/evaluation_formula_array.test.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/evaluation/evaluation_formula_array.test.ts b/tests/evaluation/evaluation_formula_array.test.ts index bf7e35c79f..32582b3c3e 100644 --- a/tests/evaluation/evaluation_formula_array.test.ts +++ b/tests/evaluation/evaluation_formula_array.test.ts @@ -1,7 +1,7 @@ import { arg, functionRegistry } from "../../src/functions"; import { toScalar } from "../../src/functions/helper_matrices"; import { toMatrix, toNumber } from "../../src/functions/helpers"; -import { toZone } from "../../src/helpers"; +import { toCartesian, toZone } from "../../src/helpers"; import { Model } from "../../src/model"; import { DEFAULT_LOCALE, ErrorCell, UID } from "../../src/types"; import { @@ -709,6 +709,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)");