Skip to content

Commit

Permalink
[FIX] Composer: F4 handler should not bubble out of the composer
Browse files Browse the repository at this point in the history
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]: #2126

closes #4221

Task: 3916488
X-original-commit: f0f1e3d
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
  • Loading branch information
rrahir committed May 15, 2024
1 parent a0aa4ca commit 0dd4e9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/composer/composer/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class Composer extends Component<ComposerProps, SpreadsheetChildEnv> {
"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"),
};
Expand Down Expand Up @@ -338,7 +338,8 @@ export class Composer extends Component<ComposerProps, SpreadsheetChildEnv> {
this.composerStore.cancelEdition();
}

private processF4Key() {
private processF4Key(ev: KeyboardEvent) {
ev.stopPropagation();
this.composerStore.cycleReferences();
this.processContent();
}
Expand Down
14 changes: 14 additions & 0 deletions tests/composer/composer_integration_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { SpreadsheetChildEnv } from "../../src/types";
import { ContentEditableHelper } from "../__mocks__/content_editable_helper";
import {
activateSheet,
copy,
createSheet,
paste,
renameSheet,
resizeColumns,
resizeRows,
Expand All @@ -35,6 +37,7 @@ import {
import {
getActivePosition,
getActiveSheetFullScrollInfo,
getCellContent,
getCellText,
getSelectionAnchorCellXc,
} from "../test_helpers/getters_helpers";
Expand Down Expand Up @@ -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";

Expand Down

0 comments on commit 0dd4e9d

Please sign in to comment.