Skip to content

Commit

Permalink
[FIX] clipboard: don't open composer on firefox
Browse files Browse the repository at this point in the history
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 #2275

X-original-commit: 81e4b9e
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
LucasLefevre committed Mar 27, 2023
1 parent b14ef0f commit 654d22f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/composer/content_editable_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/components/grid/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ export class Grid extends Component<Props, SpreadsheetChildEnv> {
}

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
Expand Down
14 changes: 14 additions & 0 deletions tests/components/grid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
});

Expand Down

0 comments on commit 654d22f

Please sign in to comment.