Skip to content

Commit 2c38d58

Browse files
committed
[FIX] composer: change mode to editing when composer cursor selection changes
Before this commit: - When typing '=sum(' and pressing the Home key, selecting a range caused weird behavior in the composer. - The same issue occurred when using Ctrl+A to select the entire text. After this commit: - Changing the cursor selection now correctly switches the mode to 'editing'. Task: 5226615
1 parent d9d0f31 commit 2c38d58

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/components/composer/composer/composer.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,7 @@ export class Composer extends Component<ComposerProps, SpreadsheetChildEnv> {
485485
}
486486
const newSelection = this.contentHelper.getCurrentSelection();
487487

488-
this.env.model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
489488
this.props.onComposerContentFocused();
490-
if (this.props.focus === "inactive") {
491-
}
492489
this.env.model.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION", newSelection);
493490
this.processTokenAtCursor();
494491
}

src/plugins/ui_stateful/edition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ 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";
147148
break;
148149
case "STOP_COMPOSER_RANGE_SELECTION":
149150
if (this.isSelectingForComposer()) {

tests/composer/autocomplete_dropdown_component.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ describe("Autocomplete parenthesis", () => {
338338
test("=S( + edit S with autocomplete does not add left parenthesis", async () => {
339339
await typeInComposer("=S(");
340340
// go behind the letter "S"
341-
model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
342341
model.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION", { start: 2, end: 2 });
343342
await nextTick();
344343
// show autocomplete

tests/composer/edition_plugin.test.ts

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

106+
test("should switch to editing mode when composer cursor selection changes", () => {
107+
const model = new Model();
108+
model.dispatch("START_EDITION", { text: "=sum(" });
109+
expect(model.getters.getEditionMode()).toBe("selecting");
110+
model.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION", { start: 0, end: 5 });
111+
expect(model.getters.getEditionMode()).toBe("editing");
112+
});
113+
106114
test("Stopping the edition should complete the missing parenthesis of a formula", async () => {
107115
const model = new Model();
108116
model.dispatch("START_EDITION", { text: "=sum(sum(1,2" });
@@ -422,10 +430,7 @@ describe("edition", () => {
422430
model.dispatch("START_EDITION");
423431
model.dispatch("SET_CURRENT_CONTENT", {
424432
content: "=",
425-
});
426-
model.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION", {
427-
start: 1,
428-
end: 1,
433+
selection: { start: 1, end: 1 },
429434
});
430435

431436
setSelection(model, ["A1:A3"]);

0 commit comments

Comments
 (0)