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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets-ui): clear stale editor undo history (#7576)
wpxp1234561d4112c4646d
diff --git a/packages/docs/src/services/doc-state-change-manager.service.ts b/packages/docs/src/services/doc-state-change-manager.service.tsindex 5241a3d809..f8990b0c35 100644--- a/packages/docs/src/services/doc-state-change-manager.service.ts+++ b/packages/docs/src/services/doc-state-change-manager.service.ts@@ -73,6 +73,10 @@ export class DocStateChangeManagerService extends RxDisposable {this._changeStateCache.set(unitId, cache.collaboration);}+ clearHistory(unitId: string): void {+ this._historyStateCache.delete(unitId);+ }+private _setChangeState(changeState: IDocStateChangeParams) {this._cacheChangeState(changeState, 'history');// Mutations by user or historyService need collaboration.diff --git a/packages/sheets-ui/src/controllers/editor/__tests__/editing-render-business.spec.ts b/packages/sheets-ui/src/controllers/editor/__tests__/editing-render-business.spec.tsindex ae5df1f06b..4224e83b11 100644--- a/packages/sheets-ui/src/controllers/editor/__tests__/editing-render-business.spec.ts+++ b/packages/sheets-ui/src/controllers/editor/__tests__/editing-render-business.spec.ts@@ -126,6 +126,9 @@ function createController(initialDataStream = 'new value\r\n', isPercentFormat =rollback: vi.fn(),clearUndoRedo: vi.fn(),};+ controller._docStateChangeManagerService = {+ clearHistory: vi.fn(),+ };controller._contextService = {setContextValue: vi.fn(),getContextValue: vi.fn(() => false),diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.tsindex 26a788c0f6..d6e6a6fda7 100644--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts@@ -67,7 +67,13 @@ import {UniverInstanceType,WrapStrategy,} from '@univerjs/core';-import { DocSelectionManagerService, DocSkeletonManagerService, InsertTextCommand, RichTextEditingMutation } from '@univerjs/docs';+import {+ DocSelectionManagerService,+ DocSkeletonManagerService,+ DocStateChangeManagerService,+ InsertTextCommand,+ RichTextEditingMutation,+} from '@univerjs/docs';import {DocSelectionRenderService,IEditorService,@@ -193,7 +199,8 @@ export class EditingRenderController extends Disposable {@Inject(SheetInterceptorService) private readonly _sheetInterceptorService: SheetInterceptorService,@Inject(SheetCellEditorResizeService) private readonly _sheetCellEditorResizeService: SheetCellEditorResizeService,@Inject(SheetsSelectionsService) private readonly _selectionManagerService: SheetsSelectionsService,- @IConfigService private readonly _configService: IConfigService+ @IConfigService private readonly _configService: IConfigService,+ @Inject(DocStateChangeManagerService) private readonly _docStateChangeManagerService: DocStateChangeManagerService) {super();@@ -524,6 +531,8 @@ export class EditingRenderController extends Disposable {const { unitId, isInArrayFormulaRange = false } = editCellState;+ this._clearEditorHistory();+this._commandService.syncExecuteCommand(ScrollToRangeOperation.id, {unitId,range: {@@ -865,8 +874,14 @@ export class EditingRenderController extends Disposable {if (editorUnitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {this._getEditorSkeleton(DOCS_NORMAL_EDITOR_UNIT_ID_KEY)?.resetInitialWidth();}- this._undoRedoService.clearUndoRedo(editorUnitId);+ this._clearEditorHistory();+ }++ private _clearEditorHistory(): void {+ this._undoRedoService.clearUndoRedo(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);this._undoRedoService.clearUndoRedo(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);+ this._docStateChangeManagerService.clearHistory(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);+ this._docStateChangeManagerService.clearHistory(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);}private _moveSelection(keycode: KeyCode | undefined, currentUnitId: string, worksheetId: string) {