From be5500d1cdd30691bd2c358d6b3d792f8e8abdd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir=20=28rar=29?= Date: Mon, 13 May 2024 09:30:11 +0200 Subject: [PATCH] [FIX] Composer: F4 handler should not bubble out of the composer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since pull request 2126[^1], the shortcut F4 is handled by the grid component. Unfortunately, the same shortcut is handled in the composer as well and its propabation was not stopped. This means that a user wanting to loop the references inside their formula could see some unexpected side effects due to the grid replaying some commands. [^1]: https://github.com/odoo/o-spreadsheet/issues/2126 closes odoo/o-spreadsheet#4201 Task: 3916488 Signed-off-by: Lucas Lefèvre (lul) --- src/components/composer/composer/composer.ts | 5 +++-- tests/components/composer_integration.test.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/composer/composer/composer.ts b/src/components/composer/composer/composer.ts index fe7b6053d..0f1d09a84 100644 --- a/src/components/composer/composer/composer.ts +++ b/src/components/composer/composer/composer.ts @@ -195,7 +195,7 @@ export class Composer extends Component { Enter: this.processEnterKey, Escape: this.processEscapeKey, F2: () => console.warn("Not implemented"), - F4: this.processF4Key, + F4: (ev: KeyboardEvent) => this.processF4Key(ev), Tab: (ev: KeyboardEvent) => this.processTabKey(ev), }; @@ -329,9 +329,10 @@ export class Composer extends Component { this.env.model.dispatch("STOP_EDITION", { cancel: true }); } - private processF4Key() { + private processF4Key(ev: KeyboardEvent) { this.env.model.dispatch("CYCLE_EDITION_REFERENCES"); this.processContent(); + ev.stopPropagation(); } onCompositionStart() { diff --git a/tests/components/composer_integration.test.ts b/tests/components/composer_integration.test.ts index 9998a96e5..286f82761 100644 --- a/tests/components/composer_integration.test.ts +++ b/tests/components/composer_integration.test.ts @@ -9,7 +9,9 @@ import { import { colors, toHex, toZone } from "../../src/helpers"; import { activateSheet, + copy, createSheet, + paste, renameSheet, resizeColumns, resizeRows, @@ -30,6 +32,7 @@ import { import { getActivePosition, getActiveSheetFullScrollInfo, + getCellContent, getCellText, getSelectionAnchorCellXc, } from "../test_helpers/getters_helpers"; @@ -474,6 +477,19 @@ describe("Grid composer", () => { expect(document.activeElement).toBe(fixture.querySelector(".o-grid div.o-composer")!); }); + test("pressing F4 loops the references without impacting the 'redo' feature of the grid", async () => { + setCellContent(model, "A1", "coucou"); + setCellContent(model, "A2", "coucou2"); + copy(model, "A1:A2"); + paste(model, "A3:A4"); + selectCell(model, "B1"); + await startComposition("=C4"); + model.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION", { start: 1, end: 1 }); + await nextTick(); + await keyDown({ key: "F4" }); + expect(getCellContent(model, "B2")).toBe(""); + }); + describe("grid composer basic style", () => { const composerContainerSelector = ".o-grid .o-grid-composer";