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(code): command code fix

jerry0aa2d99096f8
diff --git a/packages/core/src/Command/Command.ts b/packages/core/src/Command/Command.ts
index ae7c200ca5..192edc43c7 100644
--- a/packages/core/src/Command/Command.ts
+++ b/packages/core/src/Command/Command.ts
@@ -9,7 +9,6 @@ import {
ActionOperation,
CommonParameter,
} from './index';
-
import { DocumentModel } from '../Docs/Domain/DocumentModel';
export class CommandUnit {
@@ -23,59 +22,53 @@ export class CommandUnit {
*
*/
export class Command {
- _unit: CommandUnit;
+ actionDataList: IActionData[];
- _actionDataList: IActionData[];
+ unit: CommandUnit;
- _actionList: Array<ActionBase<IActionData>>;
+ actionList: Array<ActionBase<IActionData>>;
private _commonParameter = new CommonParameter();
constructor(commandUnit: CommandUnit, ...list: IActionData[]) {
- this._unit = commandUnit;
- this._actionDataList = list;
- this._actionList = [];
+ this.unit = commandUnit;
+ this.actionDataList = list;
+ this.actionList = [];
}
- getDoData(): IActionData[] {
- return this._actionList.map((action) => action.getDoActionData());
- }
-
- getOldData(): IActionData[] {
- return this._actionList.map((action) => action.getOldActionData());
- }
-
- getInjector(): CommandInjector {
- const commandThis = this;
- return new (class implements CommandInjector {
- injectAction(action: ActionBase<IActionData, IActionData, void>): void {
- commandThis._actionList.push(action);
- }
+ invoke(): void {
+ this.actionDataList.forEach((data) => {
+ const ActionClass = CommandManager.getAction(data.actionName);
+ if (!ActionClass) return;
+ const observers = CommandManager.getActionObservers();
+ const action = new ActionClass(
+ data,
+ this.unit,
+ observers,
+ this._commonParameter.reset()
+ );
- getActions(): Array<ActionBase<IActionData>> {
- return commandThis._actionList.concat([]);
- }
+ this.actionList.push(action);
+ });
- include<T>(action: Class<T>): Nullable<T> {
- for (let i = 0; i < commandThis._actionList.length; i++) {
- if (commandThis._actionList[i] instanceof action) {
- return commandThis._actionList[i] as unknown as Nullable<T>;
- }
- }
- return null;
- }
- })();
+ CommandManager.getCommandInjectorObservers().notifyObservers(
+ this.getInjector()
+ );
+ CommandManager.getCommandObservers().notifyObservers({
+ type: ActionType.REDO,
+ actions: this.actionList,
+ });
}
redo(): void {
- this._actionList.forEach((action) => {
+ this.actionList.forEach((action) => {
if (ActionOperation.hasUndo(action.getDoActionData())) {
action.redo(this._commonParameter.reset());
}
});
CommandManager.getCommandObservers().notifyObservers({
type: ActionType.REDO,
- actions: this._actionList,
+ actions: this.actionList,
});
}
@@ -84,38 +77,44 @@ export class Command {
// 1. removeColumn C:E 2.insertColumnData A,
// when undo, it should be
// 1. removeColumn A, 2. insertColumnData C:E
- this._actionList.forEach((action) => {
+ this.actionList.forEach((action) => {
if (ActionOperation.hasUndo(action.getOldActionData())) {
action.undo(this._commonParameter.reset());
}
});
CommandManager.getCommandObservers().notifyObservers({
type: ActionType.UNDO,
- actions: this._actionList,
+ actions: this.actionList,
});
}
- invoke(): void {
- this._actionDataList.forEach((data) => {
- const ActionClass = CommandManager.getAction(data.actionName);
- if (!ActionClass) return;
- const observers = CommandManager.getActionObservers();
- const action = new ActionClass(
- data,
- this._unit,
- observers,
- this._commonParameter.reset()
- );
+ getOldData(): IActionData[] {
+ return this.actionList.map((action) => action.getOldActionData());
+ }
- this._actionList.push(action);
- });
+ getDoData(): IActionData[] {
+ return this.actionList.map((action) => action.getDoActionData());
+ }
- CommandManager.getCommandInjectorObservers().notifyObservers(
- this.getInjector()
- );
- CommandManager.getCommandObservers().notifyObservers({
- type: ActionType.REDO,
- actions: this._actionList,
- });
+ getInjector(): CommandInjector {
+ const commandThis = this;
+ return new (class implements CommandInjector {
+ injectAction(action: ActionBase<IActionData, IActionData, void>): void {
+ commandThis.actionList.push(action);
+ }
+
+ getActions(): Array<ActionBase<IActionData>> {
+ return commandThis.actionList.concat([]);
+ }
+
+ include<T>(action: Class<T>): Nullable<T> {
+ for (let i = 0; i < commandThis.actionList.length; i++) {
+ if (commandThis.actionList[i] instanceof action) {
+ return commandThis.actionList[i] as unknown as Nullable<T>;
+ }
+ }
+ return null;
+ }
+ })();
}
}
diff --git a/packages/core/src/Command/CommandManager.ts b/packages/core/src/Command/CommandManager.ts
index f0db2f495e..a5027b89fe 100644
--- a/packages/core/src/Command/CommandManager.ts
+++ b/packages/core/src/Command/CommandManager.ts
@@ -81,10 +81,10 @@ export class CommandManager {
invoke(command: Command): void {
const { _undoManager } = this;
- const { _actionDataList } = command;
+ const { actionDataList } = command;
// Action may be added or reissued
- this._actionExtensionManager.handle(_actionDataList);
+ this._actionExtensionManager.handle(actionDataList);
command.invoke();