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: fix the calculation of the maximum height and width of the editor (#6615)

wpxp123456b40ae2aef47b
diff --git a/packages/sheets-ui/src/services/editor/cell-editor-resize.service.ts b/packages/sheets-ui/src/services/editor/cell-editor-resize.service.ts
index 7c0d97c90b..f54884cf68 100644
--- a/packages/sheets-ui/src/services/editor/cell-editor-resize.service.ts
+++ b/packages/sheets-ui/src/services/editor/cell-editor-resize.service.ts
@@ -16,16 +16,12 @@
import type { DocumentDataModel, IPosition, Nullable } from '@univerjs/core';
import type { DocumentSkeleton, IDocumentLayoutObject, Scene } from '@univerjs/engine-render';
-import type { IUniverUIConfig } from '@univerjs/ui';
-import type { IUniverSheetsUIConfig } from '../../controllers/config.schema';
import { Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, HorizontalAlign, IConfigService, IUniverInstanceService, UniverInstanceType, VerticalAlign, WrapStrategy } from '@univerjs/core';
import { DocSkeletonManagerService } from '@univerjs/docs';
import { DOCS_COMPONENT_MAIN_LAYER_INDEX, VIEWPORT_KEY } from '@univerjs/docs-ui';
import { convertTextRotation, fixLineWidthByScale, getCurrentTypeOfRenderer, IRenderManagerService, Rect, ScrollBar } from '@univerjs/engine-render';
-import { ILayoutService, UI_PLUGIN_CONFIG_KEY } from '@univerjs/ui';
+import { ILayoutService } from '@univerjs/ui';
import { getEditorObject } from '../../basics/editor/get-editor-object';
-import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';
-import { SHEET_FOOTER_BAR_HEIGHT } from '../../views/sheet-container/SheetContainer';
import { IEditorBridgeService } from '../editor-bridge.service';
import { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';
import { ICellEditorManagerService } from './cell-editor-manager.service';
@@ -233,39 +229,26 @@ export class SheetCellEditorResizeService extends Disposable {
// We should take the scale into account when canvas is scaled by CSS.
const widthOfCanvas = pxToNum(canvasElement.style.width); // declared width
- const { width } = canvasClientRect; // real width affected by scale
+ const { width, height } = canvasClientRect; // real width affected by scale
const scaleAdjust = width / widthOfCanvas;
const { startX, startY, endX } = position;
const enginWidth = engine.width;
- const footerBarHeight = (
- (this._configService.getConfig<IUniverUIConfig>(UI_PLUGIN_CONFIG_KEY)?.footer ?? true)
- &&
- (this._configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY)?.footer ?? true)
- )
- ? SHEET_FOOTER_BAR_HEIGHT
- : 0;
-
- const clientHeight =
- document.body.clientHeight -
- startY -
- footerBarHeight -
- canvasOffset.top -
- EDITOR_BORDER_SIZE * 2;
-
- let clientWidth = width - startX;
+ const maxHeight = height - startY - EDITOR_BORDER_SIZE * 2;
+ let maxWidth = width - startX;
if (horizontalAlign === HorizontalAlign.CENTER) {
const rightGap = enginWidth - endX;
const leftGap = startX;
- clientWidth = (endX - startX) + Math.min(leftGap, rightGap) * 2;
+ maxWidth = (endX - startX) + Math.min(leftGap, rightGap) * 2;
} else if (horizontalAlign === HorizontalAlign.RIGHT) {
- clientWidth = endX;
+ maxWidth = endX;
}
+ maxWidth = maxWidth - EDITOR_BORDER_SIZE * 2;
return {
- height: clientHeight,
- width: clientWidth - EDITOR_BORDER_SIZE,
+ height: maxHeight,
+ width: maxWidth,
scaleAdjust,
};
}