Skip to content

Commit 16b2e41

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 #7485 Task: 5226615 X-original-commit: e9da932 Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com> Signed-off-by: Ronakkumar Mukeshbhai Bharadiya (rmbh) <rmbh@odoo.com>
1 parent e4b3ebe commit 16b2e41

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
@@ -154,6 +154,7 @@ export abstract class AbstractComposerStore extends SpreadsheetStore {
154154
}
155155
this.selectionStart = start;
156156
this.selectionEnd = end;
157+
this.editionMode = "editing";
157158
this.computeFormulaCursorContext();
158159
this.computeParenthesisRelatedToCursor();
159160
this.updateAutoCompleteProvider();

src/components/composer/composer/composer.ts

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

598-
this.props.composerStore.stopComposerRangeSelection();
599598
this.props.onComposerContentFocused();
600-
601599
this.props.composerStore.changeComposerCursorSelection(newSelection.start, newSelection.end);
602600
this.processTokenAtCursor();
603601
}

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
@@ -525,7 +525,6 @@ describe("Autocomplete parenthesis", () => {
525525
test("=S( + edit S with autocomplete does not add left parenthesis", async () => {
526526
composerEl = await typeInComposer("=S(");
527527
// go behind the letter "S"
528-
composerStore.stopComposerRangeSelection();
529528
composerStore.changeComposerCursorSelection(2, 2);
530529
await nextTick();
531530
// show autocomplete

tests/composer/composer_store.test.ts

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

128+
test("should switch to editing mode when composer cursor selection changes", () => {
129+
composerStore.startEdition("=sum(");
130+
expect(composerStore.editionMode).toBe("selecting");
131+
composerStore.changeComposerCursorSelection(0, 5);
132+
expect(composerStore.editionMode).toBe("editing");
133+
});
134+
128135
test("Stopping the edition should complete the missing parenthesis of a formula", async () => {
129136
composerStore.startEdition("=sum(sum(1,2");
130137
composerStore.stopEdition();
@@ -348,7 +355,6 @@ describe("edition", () => {
348355
test("selecting insert range in selecting mode", () => {
349356
composerStore.startEdition();
350357
composerStore.setCurrentContent("=");
351-
composerStore.changeComposerCursorSelection(1, 1);
352358

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

0 commit comments

Comments
 (0)