Skip to content

Commit 8564f98

Browse files
committed
[FIX] composer: keep edition mode inactive on cursor selection change
Before this commit: - Changing the composer cursor selection triggered a switch to edition mode, even when the composer was inactive. - This caused unwanted activation of editing while simply moving the selection. After this commit: - Selection changes no longer modify the edition mode when the composer is inactive, ensuring the edition state remains stable. closes #7523 Task: 5354541 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent f0b3792 commit 8564f98

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/plugins/ui_stateful/edition.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ export class EditionPlugin extends UIPlugin {
144144
case "CHANGE_COMPOSER_CURSOR_SELECTION":
145145
this.selectionStart = cmd.start;
146146
this.selectionEnd = cmd.end;
147-
this.mode = "editing";
147+
if (this.isSelectingForComposer()) {
148+
this.mode = "editing";
149+
}
148150
break;
149151
case "STOP_COMPOSER_RANGE_SELECTION":
150152
if (this.isSelectingForComposer()) {

tests/composer/composer_integration_component.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
getElComputedStyle,
2828
gridMouseEvent,
2929
keyDown,
30+
keyUp,
3031
rightClickCell,
3132
selectColumnByClicking,
3233
simulateClick,
@@ -339,6 +340,15 @@ describe("Composer interactions", () => {
339340
expect(model.getters.getEditionMode()).toBe("inactive");
340341
});
341342

343+
test("should switch topbar composer from editing to inactive when pressing Escape on cell A1 containing '=A2'", async () => {
344+
setCellContent(model, "A1", "=A2");
345+
await click(fixture, ".o-spreadsheet-topbar .o-composer");
346+
expect(model.getters.getEditionMode()).toBe("editing");
347+
keyDown({ key: "Escape" });
348+
keyUp({ key: "Escape" });
349+
expect(model.getters.getEditionMode()).toBe("inactive");
350+
});
351+
342352
test("ArrowKeys will move to neighbour cell, if not in contentFocus mode (left/right)", async () => {
343353
let composerEl: Element;
344354
composerEl = await startComposition("a");

tests/composer/edition_plugin.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ describe("edition", () => {
103103
expect(model.getters.getEditionMode()).toBe("inactive");
104104
});
105105

106+
test("should keep edition mode inactive when selection changes while composer is inactive", () => {
107+
const model = new Model();
108+
expect(model.getters.getEditionMode()).toBe("inactive");
109+
model.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION", { start: 0, end: 0 });
110+
expect(model.getters.getEditionMode()).toBe("inactive");
111+
});
112+
106113
test("should switch to editing mode when composer cursor selection changes", () => {
107114
const model = new Model();
108115
model.dispatch("START_EDITION", { text: "=sum(" });

0 commit comments

Comments
 (0)