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(auto-fill): change apply type will undo last commands (#3311)
YuHong391c52389e39
diff --git a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.tsindex 04f01c3a14..03a424cd09 100644--- a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts+++ b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts@@ -792,14 +792,14 @@ describe('Test auto fill rules in controller', () => {// undo redoawait commandService.executeCommand(UndoCommand.id);- expect(workbook.getSheetBySheetId('sheet1')?.getCell(14, 4)?.v).toBe(6);+ expect(workbook.getSheetBySheetId('sheet1')?.getCell(14, 4)?.v).toBe(8);const styles_undo = getStyles(14, 4, 14, 4);expect(styles_undo && styles_undo[0][0]).toStrictEqual({bg: {- rgb: '#ccc',+ rgb: '#eee',},- ht: 2,- vt: 2,+ ht: null,+ vt: null,});// redodiff --git a/packages/sheets-ui/src/controllers/auto-fill.controller.ts b/packages/sheets-ui/src/controllers/auto-fill.controller.tsindex b4ab9c68e1..d62be42287 100644--- a/packages/sheets-ui/src/controllers/auto-fill.controller.ts+++ b/packages/sheets-ui/src/controllers/auto-fill.controller.ts@@ -373,6 +373,7 @@ export class AutoFillController extends Disposable {}});+ this._autoFillService.initPrevUndo();// set apply type will trigger fillDatafor (let i = 0; i < preferTypes.length; i++) {const menuItem = this._autoFillService.menu.find((m) => m.value === preferTypes[i]);diff --git a/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts b/packages/sheets-ui/src/services/auto-fill/auto-fill.service.tsindex ad1b4ca0fb..6a9da7e491 100644--- a/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts+++ b/packages/sheets-ui/src/services/auto-fill/auto-fill.service.ts@@ -80,6 +80,8 @@ export interface IAutoFillService {getActiveHooks(): ISheetAutoFillHook[];addHook(hook: ISheetAutoFillHook): IDisposable;fillData(triggerUnitId: string, triggerSubUnitId: string): boolean;++ initPrevUndo(): void;}export interface IApplyMenuItem {@@ -95,6 +97,8 @@ export class AutoFillService extends Disposable implements IAutoFillService {private readonly _applyType$: BehaviorSubject<APPLY_TYPE> = new BehaviorSubject<APPLY_TYPE>(APPLY_TYPE.SERIES);private _isFillingStyle: boolean = true;+ private _prevUndos: IMutationInfo[] = [];+private readonly _autoFillLocation$: BehaviorSubject<Nullable<IAutoFillLocation>> = new BehaviorSubject<Nullable<IAutoFillLocation>>(null);@@ -167,6 +171,11 @@ export class AutoFillService extends Disposable implements IAutoFillService {return [maxPriority];}+ // a cache to undo commands of last apply-type+ initPrevUndo() {+ this._prevUndos = [];+ }+addHook(hook: ISheetAutoFillHook) {if (this._hooks.find((h) => h.id === hook.id)) {throw new Error(`Add hook failed, hook id '${hook.id}' already exist!`);@@ -291,6 +300,13 @@ export class AutoFillService extends Disposable implements IAutoFillService {return false;}+ if (this._prevUndos.length > 0) {+ this._prevUndos.forEach((undo) => {+ this._commandService.syncExecuteCommand(undo.id, undo.params);+ });+ }+ this._prevUndos = [];+const selection = Rectangle.union(discreteRangeToRange(source), discreteRangeToRange(target));const applyType = this.applyType;const activeHooks = this.getActiveHooks();@@ -346,6 +362,8 @@ export class AutoFillService extends Disposable implements IAutoFillService {redos.push(...autoHeightUndoRedos.redos);}if (result) {+ this._prevUndos = undos;+ // add to undo redo servicesthis._undoRedoService.pushUndoRedo({unitID: unitId,undoMutations: undos,diff --git a/packages/sheets-ui/src/views/operate-container/AutoFillPopupMenu.tsx b/packages/sheets-ui/src/views/operate-container/AutoFillPopupMenu.tsxindex 16f520fd4d..c01ebac15e 100644--- a/packages/sheets-ui/src/views/operate-container/AutoFillPopupMenu.tsx+++ b/packages/sheets-ui/src/views/operate-container/AutoFillPopupMenu.tsx@@ -173,6 +173,7 @@ export const AutoFillPopupMenu: React.FC<{}> = () => {const handleClick = (item: IAutoFillPopupMenuItem) => {commandService.executeCommand(RefillCommand.id, { type: item.value });+ setVisible(false);};const showMore = visible || isHovered;