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(core/Action):add set zoom action

eiji-thf69738c3e0a6
diff --git a/packages/base-sheets/src/View/Render/CanvasView.ts b/packages/base-sheets/src/View/Render/CanvasView.ts
index 60ba96139e..7cd404c207 100644
--- a/packages/base-sheets/src/View/Render/CanvasView.ts
+++ b/packages/base-sheets/src/View/Render/CanvasView.ts
@@ -84,11 +84,11 @@ export class CanvasView {
context.getContextObserver('onZoomRatioSheetObservable').add((value) => {
const plugin = this._plugin as SpreadsheetPlugin;
this._scene.scale(value.zoomRatio, value.zoomRatio);
- this._scene.makeDirty();
+ // this._scene.makeDirty();
// update data
plugin.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.ts
index ea916eddec..87d0f79e32 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,
@@ -44,6 +44,7 @@ import { InsertSheetAction } from '../Sheets/Action/InsertSheetAction';
import { RemoveColumnAction } from '../Sheets/Action/removeColumnAction';
import { RemoveSheetAction } from '../Sheets/Action/RemoveSheetAction';
import { CommandManager } from './CommandManager';
+import { SetZoomRatioAction } from '../Sheets/Action/SetZoomRatioAction';
/**
* All Commands are registered statically. For each new Command, a static registration method must be added here.
@@ -116,3 +117,5 @@ CommandManager.register(ACTION_NAMES.SET_RANGE_NOTE_ACTION, SetRangeNoteAction);
CommandManager.register(ACTION_NAMES.INSERT_SHEET_ACTION, InsertSheetAction);
CommandManager.register(ACTION_NAMES.REMOVE_SHEET_ACTION, RemoveSheetAction);
CommandManager.register(ACTION_NAMES.SET_SHEET_ORDER_ACTION, SetSheetOrderAction);
+CommandManager.register(ACTION_NAMES.SET_SHEET_ORDER_ACTION, SetSheetOrderAction);
+CommandManager.register(ACTION_NAMES.SET_ZOOM_RATIO_ACTION, SetZoomRatioAction);
diff --git a/packages/core/src/Const/ACTION_NAMES.ts b/packages/core/src/Const/ACTION_NAMES.ts
index b355b81a9a..60231f10fc 100644
--- a/packages/core/src/Const/ACTION_NAMES.ts
+++ b/packages/core/src/Const/ACTION_NAMES.ts
@@ -46,4 +46,5 @@ export enum ACTION_NAMES {
SET_NAMED_RANGE_ACTION = 'SetNamedRangeAction',
ADD_NAMED_RANGE_ACTION = 'AddNamedRangeAction',
SET_SHEET_ORDER_ACTION = 'SetSheetOrderAction',
+ SET_ZOOM_RATIO_ACTION = 'SetZoomRatioAction',
}
diff --git a/packages/core/src/Sheets/Domain/Worksheet.ts b/packages/core/src/Sheets/Domain/Worksheet.ts
index 64764a5d98..17b73b3fbf 100644
--- a/packages/core/src/Sheets/Domain/Worksheet.ts
+++ b/packages/core/src/Sheets/Domain/Worksheet.ts
@@ -425,9 +425,16 @@ export class Worksheet {
* @param zoomRatio
*/
setZoomRatio(zoomRatio: number): void {
- const { _context } = this;
+ const { _context, _sheetId, _commandManager } = this;
+ const zoomRation = {
+ actionName: ACTION_NAMES.SET_ZOOM_RATIO_ACTION,
+ sheetId: _sheetId,
+ zoom: zoomRatio,
+ };
+ const command = new Command(_context.getWorkBook(), zoomRation);
+ _commandManager.invoke(command);
+
const observer = _context.getContextObserver('onZoomRatioSheetObservable');
- this._config.zoomRatio = zoomRatio;
observer.notifyObservers({ zoomRatio });
}