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: need to refresh cell editor size after scale (#1160)

Ran Luo6067b7dffe0d
diff --git a/packages/sheets-ui/src/commands/commands/set-zoom-ratio.command.ts b/packages/sheets-ui/src/commands/commands/set-zoom-ratio.command.ts
index 13812cb18d..aedd062736 100644
--- a/packages/sheets-ui/src/commands/commands/set-zoom-ratio.command.ts
+++ b/packages/sheets-ui/src/commands/commands/set-zoom-ratio.command.ts
@@ -47,9 +47,11 @@ export const ChangeZoomRatioCommand: ICommand<IChangeZoomRatioCommandParams> = {
const unitId = workbook.getUnitId();
const subUnitId = worksheet.getSheetId();
+ // eslint-disable-next-line no-magic-numbers
let zoom = reset ? 100 : Math.round((worksheet.getConfig().zoomRatio + delta) * 100);
zoom = Math.max(SHEET_ZOOM_RANGE[0], zoom);
zoom = Math.min(SHEET_ZOOM_RANGE[1], zoom);
+ // eslint-disable-next-line no-magic-numbers
const zoomRatio = zoom / 100;
return accessor.get(ICommandService).executeCommand(SetZoomRatioOperation.id, {
diff --git a/packages/sheets-ui/src/commands/operations/set-zoom-ratio.operation.ts b/packages/sheets-ui/src/commands/operations/set-zoom-ratio.operation.ts
index e3a24cf12c..0b1901aa0d 100644
--- a/packages/sheets-ui/src/commands/operations/set-zoom-ratio.operation.ts
+++ b/packages/sheets-ui/src/commands/operations/set-zoom-ratio.operation.ts
@@ -42,12 +42,9 @@ export const SetZoomRatioOperation: IOperation<ISetZoomRatioOperationParams> = {
type: CommandType.OPERATION,
handler: (accessor, params: ISetZoomRatioOperationParams) => {
const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);
- if (!workbook) {
- return false;
- }
- const worksheet = workbook.getSheetBySheetId(params.subUnitId);
- if (!worksheet) {
+ const worksheet = workbook?.getSheetBySheetId(params.subUnitId);
+ if (worksheet == null) {
return false;
}
diff --git a/packages/sheets-ui/src/controllers/editor-bridge.controller.ts b/packages/sheets-ui/src/controllers/editor-bridge.controller.ts
index 0cac014178..b0cebc3a92 100644
--- a/packages/sheets-ui/src/controllers/editor-bridge.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor-bridge.controller.ts
@@ -27,6 +27,7 @@ import {
import { Inject } from '@wendellhu/redi';
import { merge, takeUntil } from 'rxjs';
+import { SetZoomRatioCommand } from '../commands/commands/set-zoom-ratio.command';
import { SetActivateCellEditOperation } from '../commands/operations/activate-cell-edit.operation';
import { SetCellEditVisibleOperation } from '../commands/operations/cell-edit.operation';
import { IEditorBridgeService } from '../services/editor-bridge.service';
@@ -193,5 +194,14 @@ export class EditorBridgeController extends RxDisposable {
}
})
);
+
+ // When the zoom ratio is changed, the editor needs to be refreshed to get the latest cell size and position.
+ this.disposeWithMe(
+ this._commandService.onCommandExecuted((command: ICommandInfo) => {
+ if (command.id === SetZoomRatioCommand.id) {
+ this._editorBridgeService.refreshEditCellState();
+ }
+ })
+ );
}
}
diff --git a/packages/sheets-ui/src/views/count-bar/ZoomSlider.tsx b/packages/sheets-ui/src/views/count-bar/ZoomSlider.tsx
index 3da84b491d..54194878f7 100644
--- a/packages/sheets-ui/src/views/count-bar/ZoomSlider.tsx
+++ b/packages/sheets-ui/src/views/count-bar/ZoomSlider.tsx
@@ -24,6 +24,7 @@ import { SetZoomRatioCommand } from '../../commands/commands/set-zoom-ratio.comm
import { SetZoomRatioOperation } from '../../commands/operations/set-zoom-ratio.operation';
import { SHEET_ZOOM_RANGE } from '../../common/keys';
+// eslint-disable-next-line no-magic-numbers
const ZOOM_MAP = [50, 80, 100, 130, 150, 170, 200, 400];
export function ZoomSlider() {
@@ -52,9 +53,12 @@ export function ZoomSlider() {
function handleChange(value: number) {
setZoom(value);
const workbook = univerInstanceService.getCurrentUniverSheetInstance();
- if (!workbook) return;
- const worksheet = workbook.getActiveSheet();
- if (!worksheet) return;
+ const worksheet = workbook?.getActiveSheet();
+ if (worksheet == null) {
+ return;
+ }
+
+ // eslint-disable-next-line no-magic-numbers
const zoomRatio = value / 100;
commandService.executeCommand(SetZoomRatioCommand.id, {