Skip to content

Commit e076525

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 #7484 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 e8d8bcd commit e076525

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
@@ -143,6 +143,7 @@ export abstract class AbstractComposerStore extends SpreadsheetStore {
143143
}
144144
this.selectionStart = start;
145145
this.selectionEnd = end;
146+
this.editionMode = "editing";
146147
this.computeFormulaCursorContext();
147148
this.computeParenthesisRelatedToCursor();
148149
}

src/components/composer/composer/composer.ts

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

611-
this.props.composerStore.stopComposerRangeSelection();
612611
this.props.onComposerContentFocused();
613-
614612
this.props.composerStore.changeComposerCursorSelection(newSelection.start, newSelection.end);
615613
this.processTokenAtCursor();
616614
}

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
@@ -487,7 +487,6 @@ describe("Autocomplete parenthesis", () => {
487487
test("=S( + edit S with autocomplete does not add left parenthesis", async () => {
488488
composerEl = await typeInComposer("=S(");
489489
// go behind the letter "S"
490-
composerStore.stopComposerRangeSelection();
491490
composerStore.changeComposerCursorSelection(2, 2);
492491
await nextTick();
493492
// 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)