From 0dd4e9d9afe7a157c4d04d2022d8af2764713243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir=20=28rar=29?= Date: Mon, 13 May 2024 07:30:11 +0000 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#4221 Task: 3916488 X-original-commit: f0f1e3db6b26822ab5e24d9f8cb9aeac7f11fe7e Signed-off-by: Lucas Lefèvre (lul) Signed-off-by: Rémi Rahir (rar) --- src/components/composer/composer/composer.ts | 5 +++-- .../composer_integration_component.test.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/composer/composer/composer.ts b/src/components/composer/composer/composer.ts index 4464de6fe..5b2157861 100644 --- a/src/components/composer/composer/composer.ts +++ b/src/components/composer/composer/composer.ts @@ -207,7 +207,7 @@ export class Composer extends Component { "Ctrl+Enter": this.processNewLineEvent, Escape: this.processEscapeKey, F2: () => console.warn("Not implemented"), - F4: this.processF4Key, + F4: (ev: KeyboardEvent) => this.processF4Key(ev), Tab: (ev: KeyboardEvent) => this.processTabKey(ev, "right"), "Shift+Tab": (ev: KeyboardEvent) => this.processTabKey(ev, "left"), }; @@ -338,7 +338,8 @@ export class Composer extends Component { this.composerStore.cancelEdition(); } - private processF4Key() { + private processF4Key(ev: KeyboardEvent) { + ev.stopPropagation(); this.composerStore.cycleReferences(); this.processContent(); } diff --git a/tests/composer/composer_integration_component.test.ts b/tests/composer/composer_integration_component.test.ts index 3e70ea25b..e05d20301 100644 --- a/tests/composer/composer_integration_component.test.ts +++ b/tests/composer/composer_integration_component.test.ts @@ -13,7 +13,9 @@ import { SpreadsheetChildEnv } from "../../src/types"; import { ContentEditableHelper } from "../__mocks__/content_editable_helper"; import { activateSheet, + copy, createSheet, + paste, renameSheet, resizeColumns, resizeRows, @@ -35,6 +37,7 @@ import { import { getActivePosition, getActiveSheetFullScrollInfo, + getCellContent, getCellText, getSelectionAnchorCellXc, } from "../test_helpers/getters_helpers"; @@ -506,6 +509,17 @@ 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"); + await keyDown({ key: "F4" }); + expect(getCellContent(model, "B2")).toBe(""); + }); + describe("grid composer basic style", () => { const composerContainerSelector = ".o-grid .o-grid-composer";