Skip to content

Commit e9da932

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'. closes #7483 Task: 5226615 X-original-commit: e3c5dea Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com> Signed-off-by: Ronakkumar Mukeshbhai Bharadiya (rmbh) <rmbh@odoo.com>
1 parent 73c46b1 commit e9da932

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

src/components/composer/composer/abstract_composer_store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export abstract class AbstractComposerStore extends SpreadsheetStore {
131131
}
132132
this.selectionStart = start;
133133
this.selectionEnd = end;
134+
this.editionMode = "editing";
134135
this.computeFormulaCursorContext();
135136
this.computeParenthesisRelatedToCursor();
136137
}

src/components/composer/composer/composer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,7 @@ export class Composer extends Component<CellComposerProps, SpreadsheetChildEnv>
561561
}
562562
const newSelection = this.contentHelper.getCurrentSelection();
563563

564-
this.props.composerStore.stopComposerRangeSelection();
565564
this.props.onComposerContentFocused();
566-
567565
this.props.composerStore.changeComposerCursorSelection(newSelection.start, newSelection.end);
568566
this.processTokenAtCursor();
569567
}

src/helpers/pivot/pivot_composer_helpers.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export function insertTokenAfterArgSeparator(
5252
// replace the whole token
5353
start = tokenAtCursor.start;
5454
}
55-
this.composer.stopComposerRangeSelection();
5655
this.composer.changeComposerCursorSelection(start, end);
5756
this.composer.replaceComposerCursorSelection(value);
5857
}
@@ -75,7 +74,6 @@ export function insertTokenAfterLeftParenthesis(
7574
// replace the whole token
7675
start = tokenAtCursor.start;
7776
}
78-
this.composer.stopComposerRangeSelection();
7977
this.composer.changeComposerCursorSelection(start, end);
8078
this.composer.replaceComposerCursorSelection(value);
8179
}

tests/composer/autocomplete_dropdown_component.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ describe("Autocomplete parenthesis", () => {
495495
test("=S( + edit S with autocomplete does not add left parenthesis", async () => {
496496
composerEl = await typeInComposer("=S(");
497497
// go behind the letter "S"
498-
composerStore.stopComposerRangeSelection();
499498
composerStore.changeComposerCursorSelection(2, 2);
500499
await nextTick();
501500
// show autocomplete

tests/composer/composer_store.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ describe("edition", () => {
124124
expect(composerStore.editionMode).toBe("inactive");
125125
});
126126

127+
test("should switch to editing mode when composer cursor selection changes", () => {
128+
composerStore.startEdition("=sum(");
129+
expect(composerStore.editionMode).toBe("selecting");
130+
composerStore.changeComposerCursorSelection(0, 5);
131+
expect(composerStore.editionMode).toBe("editing");
132+
});
133+
127134
test("Stopping the edition should complete the missing parenthesis of a formula", async () => {
128135
composerStore.startEdition("=sum(sum(1,2");
129136
composerStore.stopEdition();
@@ -344,7 +351,6 @@ describe("edition", () => {
344351
test("selecting insert range in selecting mode", () => {
345352
composerStore.startEdition();
346353
composerStore.setCurrentContent("=");
347-
composerStore.changeComposerCursorSelection(1, 1);
348354

349355
setSelection(model, ["A1:A3"]);
350356
expect(composerStore.currentContent).toBe("=A1:A3");

0 commit comments

Comments
 (0)