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(sheets): disbale zoom ration on cell editing (#3596)

zhangw051094efe5bc
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 2d91f2e0d4..60a39d928d 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
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import type { ICommand } from '@univerjs/core';
-import { CommandType, ICommandService, IUniverInstanceService } from '@univerjs/core';
-
+import { CommandType, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, ICommandService, IUniverInstanceService } from '@univerjs/core';
import { getSheetCommandTarget } from '@univerjs/sheets';
+
+import type { ICommand } from '@univerjs/core';
import { SHEET_ZOOM_RANGE } from '../../common/keys';
+import { IEditorBridgeService } from '../../services/editor-bridge.service';
import { SetZoomRatioOperation } from '../operations/set-zoom-ratio.operation';
export interface ISetZoomRatioCommandParams {
@@ -55,6 +56,9 @@ export const ChangeZoomRatioCommand: ICommand<IChangeZoomRatioCommandParams> = {
zoom = Math.min(SHEET_ZOOM_RANGE[1], zoom);
const zoomRatio = zoom / 100;
+ const editorBridgeService = accessor.get(IEditorBridgeService);
+ const state = editorBridgeService.isVisible();
+ if ((state.unitId === unitId || state.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && state.visible) return false;
return accessor.get(ICommandService).executeCommand(SetZoomRatioOperation.id, {
unitId,
@@ -73,6 +77,10 @@ export const SetZoomRatioCommand: ICommand<ISetZoomRatioCommandParams> = {
}
const { unitId, subUnitId, zoomRatio } = params;
+ const editorBridgeService = accessor.get(IEditorBridgeService);
+ const state = editorBridgeService.isVisible();
+ if ((state.unitId === unitId || state.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && state.visible) return false;
+
return accessor.get(ICommandService).executeCommand(SetZoomRatioOperation.id, {
unitId,
subUnitId,
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 a63cc19bd8..6de4937d8a 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
@@ -18,7 +18,6 @@ import { CommandType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { IOperation } from '@univerjs/core';
import { SheetsZoomRenderController } from '../../controllers/render-controllers/zoom.render-controller';
-import { IEditorBridgeService } from '../../services/editor-bridge.service';
export interface ISetZoomRatioOperationParams {
zoomRatio: number;
@@ -32,10 +31,7 @@ export const SetZoomRatioOperation: IOperation<ISetZoomRatioOperationParams> = {
handler: (accessor, params: ISetZoomRatioOperationParams) => {
const renderManagerService = accessor.get(IRenderManagerService);
const renderUnit = renderManagerService.getRenderById(params.unitId);
- const editorBridgeService = accessor.get(IEditorBridgeService);
if (!renderUnit) return false;
- const state = editorBridgeService.isVisible();
- if (state.unitId === params.unitId && state.visible) return false;
return renderUnit.with(SheetsZoomRenderController).updateZoom(params.subUnitId, params.zoomRatio);
},
diff --git a/packages/sheets-ui/src/controllers/render-controllers/zoom.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/zoom.render-controller.ts
index 6f3dbac23a..33f5d8bdaf 100644
--- a/packages/sheets-ui/src/controllers/render-controllers/zoom.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/render-controllers/zoom.render-controller.ts
@@ -14,19 +14,21 @@
* limitations under the License.
*/
+import { Disposable, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, FOCUSING_SHEET, ICommandService, IContextService, Inject } from '@univerjs/core';
import type { Workbook } from '@univerjs/core';
-import { Disposable, FOCUSING_SHEET, ICommandService, IContextService, Inject } from '@univerjs/core';
import type { IRenderContext, IRenderModule, IWheelEvent } from '@univerjs/engine-render';
+import { SetZoomRatioCommand } from '../../commands/commands/set-zoom-ratio.command';
+import { IEditorBridgeService } from '../../services/editor-bridge.service';
import { SheetSkeletonManagerService } from '../../services/sheet-skeleton-manager.service';
import { getSheetObject } from '../utils/component-tools';
-import { SetZoomRatioCommand } from '../../commands/commands/set-zoom-ratio.command';
export class SheetsZoomRenderController extends Disposable implements IRenderModule {
constructor(
private readonly _context: IRenderContext<Workbook>,
@Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,
@ICommandService private readonly _commandService: ICommandService,
- @IContextService private readonly _contextService: IContextService
+ @IContextService private readonly _contextService: IContextService,
+ @IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService
) {
super();
@@ -55,6 +57,11 @@ export class SheetsZoomRenderController extends Disposable implements IRenderMod
return;
}
+ const state = this._editorBridgeService.isVisible();
+ if ((state.unitId === this._context.unitId || state.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) && state.visible) {
+ return;
+ }
+
const deltaFactor = Math.abs(e.deltaX);
let ratioDelta = deltaFactor < 40 ? 0.2 : deltaFactor < 80 ? 0.4 : 0.2;
ratioDelta *= e.deltaY > 0 ? -1 : 1;
diff --git a/packages/sheets-ui/src/views/count-bar/ZoomSlider.tsx b/packages/sheets-ui/src/views/count-bar/ZoomSlider.tsx
index 0f491b22f3..3985710cba 100644
--- a/packages/sheets-ui/src/views/count-bar/ZoomSlider.tsx
+++ b/packages/sheets-ui/src/views/count-bar/ZoomSlider.tsx
@@ -14,21 +14,24 @@
* limitations under the License.
*/
-import type { Workbook } from '@univerjs/core';
import {
+ DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
ICommandService,
IUniverInstanceService,
UniverInstanceType,
useDependency,
+ useObservable,
} from '@univerjs/core';
import { Slider } from '@univerjs/design';
import { SetWorksheetActiveOperation } from '@univerjs/sheets';
import React, { useCallback, useEffect, useState } from 'react';
+import type { Workbook } from '@univerjs/core';
import { SetZoomRatioCommand } from '../../commands/commands/set-zoom-ratio.command';
import { SetZoomRatioOperation } from '../../commands/operations/set-zoom-ratio.operation';
import { SHEET_ZOOM_RANGE } from '../../common/keys';
import { useActiveWorkbook } from '../../components/hook';
+import { IEditorBridgeService } from '../../services/editor-bridge.service';
const ZOOM_MAP = [50, 80, 100, 130, 150, 170, 200, 400];
@@ -36,6 +39,8 @@ export function ZoomSlider() {
const commandService = useDependency(ICommandService);
const univerInstanceService = useDependency(IUniverInstanceService);
const workbook = useActiveWorkbook();
+ const editorBridgeService = useDependency(IEditorBridgeService);
+ const visible = useObservable(editorBridgeService.visible$);
const getCurrentZoom = useCallback(() => {
if (!workbook) return 100;
@@ -77,8 +82,11 @@ export function ZoomSlider() {
});
}
+ const disabled = visible?.visible && (visible.unitId === workbook?.getUnitId() || visible.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
+
return (
<Slider
+ disabled={disabled}
min={SHEET_ZOOM_RANGE[0]}
value={zoom}
shortcuts={ZOOM_MAP}