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(facade): fix FWorkbook.setName implementation (#5375)

wpxp12345648e31ef4175d
diff --git a/packages/sheets/src/commands/commands/set-workbook-name.command.ts b/packages/sheets/src/commands/commands/set-workbook-name.command.ts
index d5dc4df943..c996428571 100644
--- a/packages/sheets/src/commands/commands/set-workbook-name.command.ts
+++ b/packages/sheets/src/commands/commands/set-workbook-name.command.ts
@@ -15,10 +15,11 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
-import { CommandType, ICommandService, IUniverInstanceService, sequenceExecute, UniverInstanceType } from '@univerjs/core';
-import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import type { ISetWorkbookNameMutationParams } from '../mutations/set-workbook-name.mutation';
+import { CommandType, ICommandService, IUniverInstanceService, sequenceExecute } from '@univerjs/core';
+import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';
import { SetWorkbookNameMutation } from '../mutations/set-workbook-name.mutation';
+import { getSheetCommandTargetWorkbook } from './utils/target-util';
export interface ISetWorkbookNameCommandParams {
name: string;
@@ -31,12 +32,13 @@ export interface ISetWorkbookNameCommandParams {
export const SetWorkbookNameCommand: ICommand = {
type: CommandType.COMMAND,
id: 'sheet.command.set-workbook-name',
- handler: async (accessor: IAccessor, params: ISetWorkbookNameCommandParams) => {
- const instanceService = accessor.get(IUniverInstanceService);
- const workbook = instanceService.getUnit(params.unitId, UniverInstanceType.UNIVER_SHEET);
- if (!workbook) return false;
-
+ handler: (accessor: IAccessor, params: ISetWorkbookNameCommandParams) => {
+ const commandService = accessor.get(ICommandService);
const sheetInterceptorService = accessor.get(SheetInterceptorService);
+
+ const target = getSheetCommandTargetWorkbook(accessor.get(IUniverInstanceService), params);
+ if (!target) return false;
+
const interceptedCommands = sheetInterceptorService.onCommandExecute({
id: SetWorkbookNameCommand.id,
params,
@@ -53,7 +55,6 @@ export const SetWorkbookNameCommand: ICommand = {
...interceptedCommands.redos,
];
- const commandService = accessor.get(ICommandService);
return sequenceExecute(redos, commandService).result;
},
};
diff --git a/packages/sheets/src/facade/f-workbook.ts b/packages/sheets/src/facade/f-workbook.ts
index 256309bf69..3ffd00fb56 100644
--- a/packages/sheets/src/facade/f-workbook.ts
+++ b/packages/sheets/src/facade/f-workbook.ts
@@ -21,7 +21,7 @@ import type { FontLine as _FontLine } from './f-range';
import { ICommandService, ILogService, Inject, Injector, IPermissionService, IResourceLoaderService, IUniverInstanceService, LocaleService, mergeWorksheetSnapshotWithDefault, RANGE_TYPE, RedoCommand, toDisposable, Tools, UndoCommand, UniverInstanceType } from '@univerjs/core';
import { FBaseInitialable } from '@univerjs/core/facade';
import { IDefinedNamesService } from '@univerjs/engine-formula';
-import { CopySheetCommand, getPrimaryForRange, InsertSheetCommand, RangeThemeStyle, RegisterWorksheetRangeThemeStyleCommand, RemoveSheetCommand, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetDefinedNameCommand, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetOrderCommand, SheetRangeThemeService, SheetsSelectionsService, UnregisterWorksheetRangeThemeStyleCommand, WorkbookEditablePermission } from '@univerjs/sheets';
+import { CopySheetCommand, getPrimaryForRange, InsertSheetCommand, RangeThemeStyle, RegisterWorksheetRangeThemeStyleCommand, RemoveSheetCommand, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetDefinedNameCommand, SetSelectionsOperation, SetWorkbookNameCommand, SetWorksheetActiveOperation, SetWorksheetOrderCommand, SheetRangeThemeService, SheetsSelectionsService, UnregisterWorksheetRangeThemeStyleCommand, WorkbookEditablePermission } from '@univerjs/sheets';
import { FDefinedName, FDefinedNameBuilder } from './f-defined-name';
import { FPermission } from './f-permission';
import { FRange } from './f-range';
@@ -106,8 +106,13 @@ export class FWorkbook extends FBaseInitialable {
* fWorkbook.setName('MyWorkbook');
* ```
*/
- setName(name: string): void {
- this._workbook.setName(name);
+ setName(name: string): this {
+ this._commandService.syncExecuteCommand(SetWorkbookNameCommand.id, {
+ unitId: this._workbook.getUnitId(),
+ name,
+ });
+
+ return this;
}
/**