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(editor): control state (#1649)

Univerc39799fb54cc
diff --git a/packages/ui/src/components/editor/TextEditor.tsx b/packages/ui/src/components/editor/TextEditor.tsx
index df50068195..a43e7310fa 100644
--- a/packages/ui/src/components/editor/TextEditor.tsx
+++ b/packages/ui/src/components/editor/TextEditor.tsx
@@ -233,7 +233,7 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
if (value == null) {
return;
}
- editorService.setValue(value, id);
+ editorService.setValueNoRefresh(value, id);
}, [value]);
function hasValue() {
diff --git a/packages/ui/src/services/editor/editor.service.ts b/packages/ui/src/services/editor/editor.service.ts
index 6a3e4853fa..e61d64ce66 100644
--- a/packages/ui/src/services/editor/editor.service.ts
+++ b/packages/ui/src/services/editor/editor.service.ts
@@ -279,6 +279,8 @@ export interface IEditorService {
setValue(val: string, editorUnitId?: string): void;
+ setValueNoRefresh(val: string, editorUnitId?: string): void;
+
setRichValue(body: IDocumentBody, editorUnitId?: string): void;
getFirstEditor(): Editor;
@@ -493,15 +495,15 @@ export class EditorService extends Disposable implements IEditorService, IDispos
editorUnitId = this._getCurrentEditorUnitId();
}
- if (val.substring(0, 1) === '=') {
- this.setFormula(val, editorUnitId);
- } else {
- this._setValue$.next({ body: {
- dataStream: val,
- }, editorUnitId });
- }
+ this.setValueNoRefresh(val, editorUnitId);
this._refreshValueChange(editorUnitId);
+ }
+
+ setValueNoRefresh(val: string, editorUnitId: string) {
+ this._setValue$.next({ body: {
+ dataStream: val,
+ }, editorUnitId });
this.resize(editorUnitId);
}