Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheets-ui): cursor error when edit started by fx btn (#5231)

ZhangWei60d8b8ce3d90
diff --git a/packages/docs-ui/src/commands/commands/replace-content.command.ts b/packages/docs-ui/src/commands/commands/replace-content.command.ts
index f0010cf495..d6cb490c91 100644
--- a/packages/docs-ui/src/commands/commands/replace-content.command.ts
+++ b/packages/docs-ui/src/commands/commands/replace-content.command.ts
@@ -218,6 +218,7 @@ interface ICoverContentCommandParams {
unitId: string;
body: IDocumentBody; // Do not contain `\r\n` at the end.
segmentId?: string;
+ textRanges?: ITextRangeWithStyle[];
}
// Cover all content with new body, and clear undo/redo stack.
@@ -226,8 +227,8 @@ export const CoverContentCommand: ICommand<ICoverContentCommandParams> = {
type: CommandType.COMMAND,
- handler: async (accessor, params: ICoverContentCommandParams) => {
- const { unitId, body, segmentId = '' } = params;
+ handler: (accessor, params: ICoverContentCommandParams) => {
+ const { unitId, body, segmentId = '', textRanges } = params;
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
@@ -245,6 +246,7 @@ export const CoverContentCommand: ICommand<ICoverContentCommandParams> = {
// No need to set the cursor or selection.
doMutation.params.noNeedSetTextRange = true;
doMutation.params.noHistory = true;
+ doMutation.params.textRanges = textRanges;
commandService.syncExecuteCommand<IRichTextEditingMutationParams, IRichTextEditingMutationParams>(
doMutation.id,
diff --git a/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts b/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts
index 366847735f..b9f5ed74e6 100644
--- a/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/formula-editor.controller.ts
@@ -171,11 +171,14 @@ export class FormulaEditorController extends RxDisposable {
dataStream: newContent,
},
segmentId: '',
+ textRanges,
};
- this._commandService.executeCommand(CoverContentCommand.id, coverContentParams);
+ this._commandService.syncExecuteCommand(CoverContentCommand.id, coverContentParams);
- this._textSelectionManagerService.replaceDocRanges(textRanges);
+ requestAnimationFrame(() => {
+ this._textSelectionManagerService.replaceDocRanges(textRanges);
+ });
}
});
}