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(sheet): avoid auto height too many rows (#4700)
VicKun5d036b782faa
diff --git a/packages/sheets-ui/src/controllers/auto-height.controller.ts b/packages/sheets-ui/src/controllers/auto-height.controller.tsindex 9fefdb56d2..b734820bb3 100644--- a/packages/sheets-ui/src/controllers/auto-height.controller.ts+++ b/packages/sheets-ui/src/controllers/auto-height.controller.ts@@ -24,7 +24,8 @@ import type {ISetWorksheetRowAutoHeightMutationParams,ISetWorksheetRowIsAutoHeightMutationParams,} from '@univerjs/sheets';-import { Disposable, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';+import type { IUniverSheetsUIConfig } from './config.schema';+import { Disposable, IConfigService, Inject, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';import {MoveRangeCommand,@@ -38,6 +39,7 @@ import {SheetsSelectionsService,} from '@univerjs/sheets';import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from './config.schema';export const AFFECT_LAYOUT_STYLES = ['ff', 'fs', 'tr', 'tb'];@@ -46,14 +48,25 @@ export class AutoHeightController extends Disposable {@IRenderManagerService private readonly _renderManagerService: RenderManagerService,@Inject(SheetInterceptorService) private readonly _sheetInterceptorService: SheetInterceptorService,@Inject(SheetsSelectionsService) private readonly _selectionManagerService: SheetsSelectionsService,- @Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService+ @Inject(IUniverInstanceService) private readonly _univerInstanceService: IUniverInstanceService,+ @IConfigService private readonly _configService: IConfigService) {super();this._initialize();}+ private _getRangesScope(ranges: IRange[]): number {+ let start: number | undefined;+ let end: number | undefined;+ for (const { startRow, endRow } of ranges) {+ start = start === undefined ? startRow : Math.min(start, startRow);+ end = end === undefined ? endRow : Math.max(end, endRow);+ }+ return (end as number) - (start as number) + 1;+ }+getUndoRedoParamsOfAutoHeight(ranges: IRange[]) {- const { _univerInstanceService: univerInstanceService } = this;+ const { _univerInstanceService: univerInstanceService, _configService: configService } = this;const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;const worksheet = workbook.getActiveSheet();@@ -67,6 +80,15 @@ export class AutoHeightController extends Disposable {undos: [],};}+ const config = configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);+ const count = this._getRangesScope(ranges);+ if (config?.maxAutoHeightCount! < count) {+ return {+ redos: [],+ undos: [],+ };+ }+const { skeleton } = sheetSkeletonService.getCurrentParam()!;const rowsAutoHeightInfo = skeleton.calculateAutoHeightInRange(ranges);diff --git a/packages/sheets-ui/src/controllers/config.schema.ts b/packages/sheets-ui/src/controllers/config.schema.tsindex 05dcfd2104..488a1a274a 100644--- a/packages/sheets-ui/src/controllers/config.schema.ts+++ b/packages/sheets-ui/src/controllers/config.schema.ts@@ -27,6 +27,11 @@ export interface IUniverSheetsUIConfig {disableAutoFocus?: true;override?: DependencyOverride;customComponents?: Set<string>;+ /**+ * The maximum count of rows triggering auto height. This is used to avoid performance issue.+ * @default 1000+ */+ maxAutoHeightCount?: number;/*** Whether to show the formula bar.@@ -42,4 +47,5 @@ export interface IUniverSheetsUIConfig {export const defaultPluginConfig: IUniverSheetsUIConfig = {formulaBar: true,+ maxAutoHeightCount: 1000,};