From 5ca9bb4ac4b6049b7c8af49c1bb9cf2b5f1e0b8c Mon Sep 17 00:00:00 2001 From: dhrp-odoo Date: Tue, 26 Mar 2024 09:22:25 +0000 Subject: [PATCH] [FIX] Composer: pressing enter in the link editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, pressing Enter in the link editor would inadvertently open the grid composer in edit mode, which was not the expected behavior. This commit addresses the issue by adding a check in the onInput method of the composer component. closes odoo/o-spreadsheet#4002 Taskid: 3796114 X-original-commit: 9fcb43d2f12824940f47e2d7116761e22e18b3be Signed-off-by: RĂ©mi Rahir (rar) --- .../link/link_editor/link_editor.ts | 1 + tests/components/composer.test.ts | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/components/link/link_editor/link_editor.ts b/src/components/link/link_editor/link_editor.ts index 65efcf41b..60b4e3787 100644 --- a/src/components/link/link_editor/link_editor.ts +++ b/src/components/link/link_editor/link_editor.ts @@ -188,6 +188,7 @@ export class LinkEditor extends Component this.save(); } ev.stopPropagation(); + ev.preventDefault(); break; case "Escape": this.cancel(); diff --git a/tests/components/composer.test.ts b/tests/components/composer.test.ts index b35e0a487..27df2f37e 100644 --- a/tests/components/composer.test.ts +++ b/tests/components/composer.test.ts @@ -26,7 +26,12 @@ import { getEvaluatedCell, getSelectionAnchorCellXc, } from "../test_helpers/getters_helpers"; -import { mountComponent, nextTick, typeInComposerHelper } from "../test_helpers/helpers"; +import { + mountComponent, + mountSpreadsheet, + nextTick, + typeInComposerHelper, +} from "../test_helpers/helpers"; import { ContentEditableHelper } from "./__mocks__/content_editable_helper"; jest.mock("../../src/components/composer/content_editable_helper", () => require("./__mocks__/content_editable_helper") @@ -520,6 +525,20 @@ describe("composer", () => { expect(link?.url).toBe("http://odoo.com"); }); + test("Pressing Enter while editing a label does not open grid composer", async () => { + ({ model, fixture } = await mountSpreadsheet()); + setCellContent(model, "A1", "[label](http://odoo.com)"); + await simulateClick(".o-topbar-menu[data-id='insert']"); + await simulateClick(".o-menu-item[data-name='insert_link']"); + const editor = fixture.querySelector(".o-link-editor"); + expect(editor).toBeTruthy(); + + editor!.querySelectorAll("input")[0].focus(); + await keyDown({ key: "Enter" }); + expect(fixture.querySelector(".o-link-editor")).toBeFalsy(); + expect(model.getters.getEditionMode()).toBe("inactive"); + }); + describe("change selecting mode when typing specific token value", () => { const matchingValues = [",", "+", "*", "="]; const mismatchingValues = ["1", '"coucou"', "TRUE", "SUM", "A2"];