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(core/Action):add set zoom action
eiji-tha6d1ab78b527
diff --git a/packages/base-sheets/src/View/Render/CanvasView.ts b/packages/base-sheets/src/View/Render/CanvasView.tsindex bf68113deb..60ba96139e 100644--- a/packages/base-sheets/src/View/Render/CanvasView.ts+++ b/packages/base-sheets/src/View/Render/CanvasView.ts@@ -88,7 +88,7 @@ export class CanvasView {// update dataplugin.getCanvasView().updateToSheet(this._plugin.getContext().getWorkBook().getActiveSheet()!);// update render- // plugin.getMainComponent().makeDirty(true);+ plugin.getMainComponent().makeDirty(true);});scene.addViewport(viewMain, viewLeft, viewTop, viewLeftTop).attachControl();diff --git a/packages/core/src/Command/RegisterAction.ts b/packages/core/src/Command/RegisterAction.tsindex e322a1f9ff..418db6ba5c 100644--- a/packages/core/src/Command/RegisterAction.ts+++ b/packages/core/src/Command/RegisterAction.ts@@ -1,4 +1,4 @@-import { ACTION_NAMES } from '../Const';+ import { ACTION_NAMES } from '../Const';import {AddNamedRangeAction,DeleteNamedRangeAction,diff --git a/packages/core/src/Sheets/Action/SetZoomRatioAction.ts b/packages/core/src/Sheets/Action/SetZoomRatioAction.tsnew file mode 100644index 0000000000..ed042b92a3--- /dev/null+++ b/packages/core/src/Sheets/Action/SetZoomRatioAction.ts@@ -0,0 +1,69 @@+import { ActionBase, ActionObservers, ActionType, IActionData } from '../../Command';+import { Workbook } from '../Domain';+import { SetZoomRatio } from '../Apply/SetZoomRatio';++export interface ISetZoomRatioActionData extends IActionData {+ zoom: number;+ sheetId: string;+}++export class SetZoomRatioAction extends ActionBase<+ ISetZoomRatioActionData,+ ISetZoomRatioActionData+> {+ constructor(+ actionData: ISetZoomRatioActionData,+ workbook: Workbook,+ observers: ActionObservers+ ) {+ super(actionData, workbook, observers);+ this._doActionData = {+ ...actionData,+ convertor: [],+ };+ this._oldActionData = {+ ...actionData,+ zoom: this.do(),+ convertor: [],+ };+ this.validate();+ }++ redo(): number {+ const result = SetZoomRatio(+ this.getWorkBook(),+ this._doActionData.sheetId,+ this._doActionData.zoom+ );++ this._observers.notifyObservers({+ type: ActionType.REDO,+ data: this._doActionData,+ action: this,+ });++ return result;+ }++ do(): number {+ return this.redo();+ }++ undo(): void {+ SetZoomRatio(+ this.getWorkBook(),+ this._oldActionData.sheetId,+ this._oldActionData.zoom+ );++ this._observers.notifyObservers({+ type: ActionType.REDO,+ data: this._oldActionData,+ action: this,+ });+ }++ validate(): boolean {+ return false;+ }+}diff --git a/packages/core/src/Sheets/Apply/SetZoomRatio.ts b/packages/core/src/Sheets/Apply/SetZoomRatio.tsnew file mode 100644index 0000000000..a773762168--- /dev/null+++ b/packages/core/src/Sheets/Apply/SetZoomRatio.ts@@ -0,0 +1,15 @@+import { Workbook } from '../Domain';++export function SetZoomRatio(+ workbook: Workbook,+ sheetId: string,+ zoom: number+): number {+ const worksheet = workbook.getSheetBySheetId(sheetId);+ if (worksheet) {+ const order = worksheet.getConfig().zoomRatio;+ worksheet.getConfig().zoomRatio = zoom;+ return order;+ }+ return 1;+}