From 654d22fc15a961a54faf74f7ec2ba0497aa17dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Tue, 21 Mar 2023 15:57:28 +0000 Subject: [PATCH] [FIX] clipboard: don't open composer on firefox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - open a spreadsheet with firefox - copy a cell - paste it somewhere else => the composer is open with the pasted content. Additional small fix in the content editable helper, the selection `start` was not clipped if it was greater than the content length. Note: it doesn't happen on Chrome because `ev.data` is null when pasting content. It doesn't correctly implements the spec https://w3c.github.io/input-events/#dfn-data opw-3236303 closes odoo/o-spreadsheet#2275 X-original-commit: 81e4b9e0edc8ef1bd06fdb14366edd3477269375 Signed-off-by: Rémi Rahir (rar) Signed-off-by: Lucas Lefèvre (lul) --- src/components/composer/content_editable_helper.ts | 1 + src/components/grid/grid.ts | 4 ++++ tests/components/grid.test.ts | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/components/composer/content_editable_helper.ts b/src/components/composer/content_editable_helper.ts index 3ab9536a4..f114cf4c4 100644 --- a/src/components/composer/content_editable_helper.ts +++ b/src/components/composer/content_editable_helper.ts @@ -32,6 +32,7 @@ export class ContentEditableHelper { ); if (start < 0) start = 0; if (end > textLength) end = textLength; + if (start > textLength) start = textLength; } let startNode = this.findChildAtCharacterIndex(start); let endNode = this.findChildAtCharacterIndex(end); diff --git a/src/components/grid/grid.ts b/src/components/grid/grid.ts index 36ac022b1..75e30df4d 100644 --- a/src/components/grid/grid.ts +++ b/src/components/grid/grid.ts @@ -466,6 +466,10 @@ export class Grid extends Component { } onInput(ev: InputEvent) { + // the user meant to paste in the sheet, not open the composer with the pasted content + if (!ev.isComposing && ev.inputType === "insertFromPaste") { + return; + } if (ev.data) { // if the user types a character on the grid, it means he wants to start composing the selected cell with that // character diff --git a/tests/components/grid.test.ts b/tests/components/grid.test.ts index 5656a9695..1d5084020 100644 --- a/tests/components/grid.test.ts +++ b/tests/components/grid.test.ts @@ -759,6 +759,20 @@ describe("Grid component", () => { await nextTick(); expect(fixture.querySelector(".o-menu")).toBeTruthy(); }); + + test("input event triggered from a paste should not open composer", async () => { + const input = fixture.querySelector(".o-grid>input"); + input?.dispatchEvent( + new InputEvent("input", { + data: "d", + bubbles: true, + isComposing: false, + inputType: "insertFromPaste", + }) + ); + await nextTick(); + expect(model.getters.getEditionMode()).toBe("inactive"); + }); }); });