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
feat: add configurable line gaps to sheet cell text (#7841)
白熱44cbc6646ecd
diff --git a/packages/core/src/common/const.ts b/packages/core/src/common/const.tsindex 71999c0821..5cb8e7cea4 100644--- a/packages/core/src/common/const.ts+++ b/packages/core/src/common/const.ts@@ -28,6 +28,8 @@ export const IS_ROW_STYLE_PRECEDE_COLUMN_STYLE = 'isRowStylePrecedeColumnStyle';export const AUTO_HEIGHT_FOR_MERGED_CELLS = Symbol('AUTO_HEIGHT_FOR_MERGED_CELLS');+export const SHEET_TEXT_LINE_GAP = Symbol('SHEET_TEXT_LINE_GAP');+export function createInternalEditorID(id: string) {return `${PREFIX}${id}`;}diff --git a/packages/docs-ui/src/__tests__/mobile-plugin.spec.ts b/packages/docs-ui/src/__tests__/mobile-plugin.spec.tsdeleted file mode 100644index 3624877e07..0000000000--- a/packages/docs-ui/src/__tests__/mobile-plugin.spec.ts+++ /dev/null@@ -1,44 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { IConfigService, Univer, UniverInstanceType } from '@univerjs/core';-import { UniverDocsPlugin } from '@univerjs/docs';-import { UniverRenderEnginePlugin } from '@univerjs/engine-render';-import { UniverMobileUIPlugin } from '@univerjs/ui';-import { expect, it, onTestFinished } from 'vitest';-import { DOCS_UI_PLUGIN_CONFIG_KEY } from '../config/config';-import { UniverDocsMobileUIPlugin } from '../mobile-plugin';--it.each([undefined, {}, { fitToWidth: { paddingX: 32 } }])('keeps mobile fit-to-width defaults when registered with %j', (config) => {- const univer = new Univer();- onTestFinished(() => univer.dispose());- univer.registerPlugin(UniverRenderEnginePlugin);- univer.registerPlugin(UniverMobileUIPlugin);- univer.registerPlugin(UniverDocsPlugin);- univer.registerPlugin(UniverDocsMobileUIPlugin, config);- univer.createUnit(UniverInstanceType.UNIVER_DOC, { id: 'doc-1' });- const configService = univer.__getInjector().get(IConfigService);- expect(configService.getConfig(DOCS_UI_PLUGIN_CONFIG_KEY)).toMatchObject({- fitToWidth: {- mode: 'fit-width',- target: 'viewport',- paddingX: config?.fitToWidth?.paddingX ?? 12,- minScale: 0,- maxScale: 1,- align: 'center',- },- });-});diff --git a/packages/docs/src/__tests__/docs.integration.spec.ts b/packages/docs/src/__tests__/docs.integration.spec.tsdeleted file mode 100644index fbc28887ff..0000000000--- a/packages/docs/src/__tests__/docs.integration.spec.ts+++ /dev/null@@ -1,459 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { DocumentDataModel, ICustomRangeForInterceptor, IDocumentData, IInterceptor } from '@univerjs/core';-import type { IRenderContext } from '@univerjs/engine-render';-import {- awaitTime,- CustomRangeType,- DisposableCollection,- ICommandService,- IUniverInstanceService,- LifecycleService,- LifecycleStages,- LocaleService,- Univer,- UniverInstanceType,-} from '@univerjs/core';-import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';-import { BehaviorSubject } from 'rxjs';-import { afterEach, beforeEach, describe, expect, it } from 'vitest';-import { DocsRenameMutation } from '../commands/mutations/docs-rename.mutation';-import { SetTextSelectionsOperation } from '../commands/operations/text-selection.operation';-import { UniverDocsPlugin } from '../plugin';-import { DocInterceptorService } from '../services/doc-interceptor/doc-interceptor.service';-import { DOC_INTERCEPTOR_POINT } from '../services/doc-interceptor/interceptor-const';-import { DocLayoutExecutorService } from '../services/doc-layout-executor.service';-import { DocSelectionManagerService } from '../services/doc-selection-manager.service';-import { DocSkeletonManagerService } from '../services/doc-skeleton-manager.service';-import { DocStateChangeManagerService } from '../services/doc-state-change-manager.service';-import { DocStateEmitService } from '../services/doc-state-emit.service';-import { DocViewModelManagerService } from '../services/doc-view-model-manager.service';-import { addCustomRangeBySelectionFactory, deleteCustomRangeFactory } from '../utils/custom-range-factory';-import { replaceSelectionFactory } from '../utils/replace-selection-factory';--function registerRenderManagerForDoc(- injector: ReturnType<Univer['__getInjector']>,- doc: DocumentDataModel-) {- const univerInstanceService = injector.get(IUniverInstanceService);- const context: IRenderContext<DocumentDataModel> = {- unitId: doc.getUnitId(),- unit: doc,- } as never;-- const skeletonManager = new DocSkeletonManagerService(- context,- injector.get(LocaleService),- univerInstanceService,- injector.get(DocLayoutExecutorService)- );-- injector.add([IRenderManagerService, { useClass: RenderManagerService }]);- injector.get(IRenderManagerService).addRender(doc.getUnitId(), {- unitId: doc.getUnitId(),- type: UniverInstanceType.UNIVER_DOC,- engine: new DisposableCollection() as never,- scene: new DisposableCollection() as never,- mainComponent: null,- components: new Map(),- isMainScene: true,- activated$: new BehaviorSubject(true),- with: <T>() => skeletonManager as T,- activate: () => {},- deactivate: () => {},- isDisposed: () => false,- });-- return skeletonManager;-}--function createTestDocData(id: string): IDocumentData {- return {- id,- body: {- dataStream: 'Hello\r\n',- customRanges: [{- startIndex: 0,- endIndex: 4,- rangeId: 'range-1',- rangeType: CustomRangeType.HYPERLINK,- wholeEntity: true,- properties: { url: 'https://example.invalid' },- }],- },- documentStyle: {- pageSize: { width: 100, height: 100 },- marginTop: 0,- marginBottom: 0,- marginLeft: 0,- marginRight: 0,- },- };-}--describe('docs integration', () => {- let univer: Univer;- let injector: ReturnType<Univer['__getInjector']>;-- beforeEach(() => {- univer = new Univer();- injector = univer.__getInjector();- injector.get(LifecycleService).stage = LifecycleStages.Starting;- });-- afterEach(() => {- univer.dispose();- });-- it('renames doc through command service mutation', async () => {- univer.registerPlugin(UniverDocsPlugin);- const doc = univer.createUnit<IDocumentData, DocumentDataModel>(- UniverInstanceType.UNIVER_DOC,- createTestDocData('doc-1')- );-- const univerInstanceService = injector.get(IUniverInstanceService);- univerInstanceService.focusUnit(doc.getUnitId());-- const commandService = injector.get(ICommandService);- const ok = await commandService.executeCommand(DocsRenameMutation.id, {- unitId: doc.getUnitId(),- name: 'Renamed',- });-- expect(ok).toBeTruthy();- expect(doc.getTitle()).toBe('Renamed');- });-- it('manages selections and emits selection operations via real command flow', async () => {- univer.registerPlugin(UniverDocsPlugin);- const doc = univer.createUnit<IDocumentData, DocumentDataModel>(- UniverInstanceType.UNIVER_DOC,- createTestDocData('doc-2')- );-- const univerInstanceService = injector.get(IUniverInstanceService);- univerInstanceService.focusUnit(doc.getUnitId());-- const commandService = injector.get(ICommandService);-- const selectionManager = injector.get(DocSelectionManagerService);- selectionManager.__TEST_ONLY_setCurrentSelection({- unitId: doc.getUnitId(),- subUnitId: doc.getUnitId(),- });-- selectionManager.__TEST_ONLY_add([- {- startOffset: 5,- endOffset: 5,- collapsed: true,- isActive: true,- segmentId: '',- style: null as never,- },- {- startOffset: 0,- endOffset: 2,- collapsed: false,- isActive: false,- segmentId: '',- style: null as never,- },- ]);-- expect(selectionManager.getActiveTextRange()?.startOffset).toBe(5);- expect(selectionManager.getDocRanges()?.map((r) => r.startOffset)).toEqual([0, 5]);-- const refreshLogs: unknown[] = [];- const refreshSub = selectionManager.refreshSelection$.subscribe((v) => v && refreshLogs.push(v));- selectionManager.replaceDocRanges([- { startOffset: 1, endOffset: 1, collapsed: true, segmentId: '' },- ] as never);-- expect(refreshLogs.length).toBeGreaterThan(0);- refreshSub.unsubscribe();-- const executed: Array<{ id: string; params: unknown }> = [];- const dispose = commandService.onCommandExecuted((info) => executed.push({ id: info.id, params: info.params }));-- selectionManager.__replaceTextRangesWithNoRefresh(- {- segmentId: '',- segmentPage: -1,- style: null as never,- textRanges: [{ startOffset: 2, endOffset: 3, collapsed: false, segmentId: '' }] as never,- rectRanges: [],- isEditing: true,- },- { unitId: doc.getUnitId(), subUnitId: doc.getUnitId() }- );-- await awaitTime(0);- expect(executed.some((e) => e.id === SetTextSelectionsOperation.id)).toBe(true);- dispose.dispose();- });-- it('replaces a selection through the factory-generated rich text mutation', async () => {- univer.registerPlugin(UniverDocsPlugin);- const doc = univer.createUnit<IDocumentData, DocumentDataModel>(- UniverInstanceType.UNIVER_DOC,- createTestDocData('doc-2a')- );-- const univerInstanceService = injector.get(IUniverInstanceService);- univerInstanceService.focusUnit(doc.getUnitId());- const skeletonManager = registerRenderManagerForDoc(injector, doc);-- const selectionManager = injector.get(DocSelectionManagerService);- selectionManager.__TEST_ONLY_setCurrentSelection({- unitId: doc.getUnitId(),- subUnitId: doc.getUnitId(),- });- selectionManager.__TEST_ONLY_add([{- startOffset: 5,- endOffset: 5,- collapsed: true,- isActive: true,- segmentId: '',- style: null as never,- }]);-- const docStateEmitService = injector.get(DocStateEmitService);- const stateChanges: unknown[] = [];- const sub = docStateEmitService.docStateChangeParams$.subscribe((value) => value && stateChanges.push(value));-- const mutation = replaceSelectionFactory(injector as never, {- unitId: doc.getUnitId(),- body: {- dataStream: ' world',- },- });-- expect(mutation).not.toBe(false);- if (mutation === false) {- throw new Error('Expected replaceSelectionFactory to create a mutation.');- }- expect(mutation.params.textRanges?.[0]?.startOffset).toBe(11);-- const commandService = injector.get(ICommandService);- const ok = await commandService.executeCommand(mutation.id, {- ...mutation.params,- trigger: 'integration-spec' as never,- });-- await awaitTime(0);-- expect(ok).toBeTruthy();- expect(doc.getBody()?.dataStream).toBe('Hello world\r\n');- expect(stateChanges).toHaveLength(1);-- sub.unsubscribe();- skeletonManager.dispose();- });-- it('emits composed doc state changes from the docs package without docs-ui', async () => {- univer.registerPlugin(UniverDocsPlugin);- const doc = univer.createUnit<IDocumentData, DocumentDataModel>(- UniverInstanceType.UNIVER_DOC,- createTestDocData('doc-state-change')- );-- const univerInstanceService = injector.get(IUniverInstanceService);- univerInstanceService.focusUnit(doc.getUnitId());- const skeletonManager = registerRenderManagerForDoc(injector, doc);-- const selectionManager = injector.get(DocSelectionManagerService);- selectionManager.__TEST_ONLY_setCurrentSelection({- unitId: doc.getUnitId(),- subUnitId: doc.getUnitId(),- });- selectionManager.__TEST_ONLY_add([{- startOffset: 5,- endOffset: 5,- collapsed: true,- isActive: true,- segmentId: '',- style: null as never,- }]);-- const docStateChangeManagerService = injector.get(DocStateChangeManagerService);- const stateChanges: unknown[] = [];- const sub = docStateChangeManagerService.docStateChange$.subscribe((value) => value && stateChanges.push(value));-- const mutation = replaceSelectionFactory(injector as never, {- unitId: doc.getUnitId(),- body: {- dataStream: ' from docs',- },- });-- expect(mutation).not.toBe(false);- if (mutation === false) {- throw new Error('Expected replaceSelectionFactory to create a mutation.');- }-- const commandService = injector.get(ICommandService);- const ok = await commandService.executeCommand(mutation.id, {- ...mutation.params,- debounce: false,- trigger: 'doc-state-change-spec' as never,- });-- await awaitTime(0);-- expect(ok).toBeTruthy();- expect(stateChanges).toHaveLength(1);- expect(doc.getBody()?.dataStream).toBe('Hello from docs\r\n');-- sub.unsubscribe();- skeletonManager.dispose();- });-- it('adds and removes custom ranges through the same mutation pipeline', async () => {- univer.registerPlugin(UniverDocsPlugin);- const doc = univer.createUnit<IDocumentData, DocumentDataModel>(- UniverInstanceType.UNIVER_DOC,- createTestDocData('doc-2b')- );-- const univerInstanceService = injector.get(IUniverInstanceService);- univerInstanceService.focusUnit(doc.getUnitId());- const skeletonManager = registerRenderManagerForDoc(injector, doc);-- const selectionManager = injector.get(DocSelectionManagerService);- selectionManager.__TEST_ONLY_setCurrentSelection({- unitId: doc.getUnitId(),- subUnitId: doc.getUnitId(),- });- selectionManager.__TEST_ONLY_add([{- startOffset: 0,- endOffset: 4,- collapsed: false,- isActive: true,- segmentId: '',- style: null as never,- }]);-- const commandService = injector.get(ICommandService);- const addMutation = addCustomRangeBySelectionFactory(injector as never, {- unitId: doc.getUnitId(),- rangeId: 'range-2',- rangeType: CustomRangeType.HYPERLINK,- wholeEntity: true,- properties: {- url: 'https://added.invalid',- },- });-- expect(addMutation).not.toBe(false);- if (addMutation === false) {- throw new Error('Expected addCustomRangeBySelectionFactory to create a mutation.');- }- await commandService.executeCommand(addMutation.id, addMutation.params);-- expect(doc.getBody()?.customRanges?.find((range) => range.rangeId === 'range-2')?.properties).toEqual({- url: 'https://added.invalid',- });-- const deleteMutation = deleteCustomRangeFactory(injector as never, {- unitId: doc.getUnitId(),- rangeId: 'range-2',- });-- expect(deleteMutation).not.toBe(false);- if (deleteMutation === false) {- throw new Error('Expected deleteCustomRangeFactory to create a mutation.');- }- await commandService.executeCommand(deleteMutation.id, deleteMutation.params);-- expect(doc.getBody()?.customRanges?.some((range) => range.rangeId === 'range-2')).toBe(false);- skeletonManager.dispose();- });-- it('builds skeleton/view-model and applies interceptors for custom ranges', () => {- injector.add([DocLayoutExecutorService]);- const doc = univer.createUnit<IDocumentData, DocumentDataModel>(- UniverInstanceType.UNIVER_DOC,- createTestDocData('doc-3')- );-- const univerInstanceService = injector.get(IUniverInstanceService);- univerInstanceService.focusUnit(doc.getUnitId());-- const context: IRenderContext<DocumentDataModel> = {- unitId: doc.getUnitId(),- unit: doc,- } as never;-- const skeletonManager = new DocSkeletonManagerService(- context,- injector.get(LocaleService),- univerInstanceService,- injector.get(DocLayoutExecutorService)- );-- const viewModelManager = new DocViewModelManagerService(context, univerInstanceService);- expect(viewModelManager.getViewModel(doc.getUnitId())).toBeDefined();-- const interceptorService = new DocInterceptorService(context, skeletonManager);- interceptorService.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {- priority: 10,- handler: (range, ctx, next) => {- const nextRange = next(range);- return nextRange ? { ...nextRange, properties: { ...nextRange.properties, unitId: ctx.unitId } } : nextRange;- },- } as IInterceptor<ICustomRangeForInterceptor, {- index: number;- unitId: string;- customRanges: ICustomRangeForInterceptor[];- }>);-- interceptorService.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {- priority: -10,- handler: (range, _ctx, next) => {- const nextRange = next(range);- return nextRange ? { ...nextRange, properties: { ...nextRange.properties, tagged: true } } : nextRange;- },- } as IInterceptor<ICustomRangeForInterceptor, {- index: number;- unitId: string;- customRanges: ICustomRangeForInterceptor[];- }>);-- const range = skeletonManager.getViewModel().getCustomRange(1);- expect(range?.rangeId).toBe('range-1');- expect(range?.properties).toMatchObject({ unitId: doc.getUnitId(), tagged: true });-- const docStateEmitService = new DocStateEmitService();- const values: unknown[] = [];- const sub = docStateEmitService.docStateChangeParams$.subscribe((v) => v && values.push(v));- docStateEmitService.emitStateChangeInfo({- commandId: 'test',- unitId: doc.getUnitId(),- trigger: null,- redoState: { actions: [], textRanges: null },- undoState: { actions: [], textRanges: null },- });- expect(values.length).toBe(1);- sub.unsubscribe();-- interceptorService.dispose();- viewModelManager.dispose();- skeletonManager.dispose();- });-});diff --git a/packages/docs/src/services/__tests__/doc-skeleton-manager.service.spec.ts b/packages/docs/src/services/__tests__/doc-skeleton-manager.service.spec.tsindex 499f23b151..a81878a640 100644--- a/packages/docs/src/services/__tests__/doc-skeleton-manager.service.spec.ts+++ b/packages/docs/src/services/__tests__/doc-skeleton-manager.service.spec.ts@@ -20,6 +20,8 @@ import {ConfigService,ContextService,DesktopLogService,+ DOCS_COMMENT_EDITOR_UNIT_ID_KEY,+ DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,DOCS_NORMAL_EDITOR_UNIT_ID_KEY,DocumentDataModel,DocumentFlavor,@@ -30,6 +32,7 @@ import {Injector,IUniverInstanceService,LocaleService,+ SHEET_TEXT_LINE_GAP,UniverInstanceService,UniverInstanceType,} from '@univerjs/core';@@ -89,7 +92,7 @@ function createExecutor(): IDocLayoutExecutor {};}-function createService(document: DocumentDataModel, registerExecutor = false) {+function createService(document: DocumentDataModel, registerExecutor = false, textLineGap = 0) {const injector = new Injector();injector.add([IContextService, { useClass: ContextService }]);injector.add([IConfigService, { useClass: ConfigService }]);@@ -98,6 +101,7 @@ function createService(document: DocumentDataModel, registerExecutor = false) {injector.add([LocaleService]);injector.add([IUniverInstanceService, { useClass: UniverInstanceService }]);injector.add([DocLayoutExecutorService]);+ injector.get(IConfigService).setConfig(SHEET_TEXT_LINE_GAP, textLineGap);const univerInstanceService = injector.get(IUniverInstanceService) as UniverInstanceService;univerInstanceService.__addUnit(document);if (registerExecutor) {@@ -211,4 +215,39 @@ describe('DocSkeletonManagerService', () => {expect(service.supportsIncrementalLayout()).toBe(false);expect(service.getSkeleton().getSkeletonData()).not.toBeNull();});++ it.each([+ [DOCS_NORMAL_EDITOR_UNIT_ID_KEY, 4],+ [DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, 4],+ [DOCS_COMMENT_EDITOR_UNIT_ID_KEY, 0],+ ['ordinary-document', 0],+ ])('applies sheet line gaps only to the cell and formula editors: %s', (id, heightChange) => {+ const injector = new Injector();+ const document = injector.createInstance(DocumentDataModel, {+ id,+ body: {+ dataStream: 'one\rtwo\rthree\r\n',+ paragraphs: [{ startIndex: 3, paragraphId: 'one' }, { startIndex: 7, paragraphId: 'two' }, { startIndex: 13, paragraphId: 'three' }],+ sectionBreaks: [{ startIndex: 14, sectionId: 'section' }],+ },+ documentStyle: { documentFlavor: DocumentFlavor.UNSPECIFIED, pageSize: { width: 400, height: Infinity } },+ });+ const baseline = createService(document);+ const spaced = createService(document, false, 2);+ try {+ const oldPage = baseline.getSkeleton().getSkeletonData()!.pages[0];+ const newPage = spaced.getSkeleton().getSkeletonData()!.pages[0];+ expect(newPage.height).toBeCloseTo(oldPage.height + heightChange);+ const oldLines = oldPage.sections[0].columns[0].lines;+ const newLines = newPage.sections[0].columns[0].lines;+ expect(newLines).toHaveLength(3);+ newLines.forEach((line, index) => {+ expect(line.top + line.marginTop - oldLines[index].top - oldLines[index].marginTop).toBeCloseTo(index * heightChange / 2);+ });+ } finally {+ spaced.dispose();+ baseline.dispose();+ injector.dispose();+ }+ });});diff --git a/packages/docs/src/services/doc-skeleton-manager.service.ts b/packages/docs/src/services/doc-skeleton-manager.service.tsindex d91b785865..eb51d77386 100644--- a/packages/docs/src/services/doc-skeleton-manager.service.ts+++ b/packages/docs/src/services/doc-skeleton-manager.service.ts@@ -17,12 +17,16 @@import type { DocumentDataModel, Nullable } from '@univerjs/core';import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';import {+ DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,+ DOCS_NORMAL_EDITOR_UNIT_ID_KEY,DocumentFlavor,+ IConfigService,Inject,isInternalEditorID,IUniverInstanceService,LocaleService,RxDisposable,+ SHEET_TEXT_LINE_GAP,UniverInstanceType,} from '@univerjs/core';import { DocumentSkeleton, DocumentViewModel, getDocumentLayoutPresentation } from '@univerjs/engine-render';@@ -51,7 +55,8 @@ export class DocSkeletonManagerService extends RxDisposable implements IRenderMoprivate readonly _context: Pick<IRenderContext<DocumentDataModel>, 'type' | 'unit' | 'unitId'>,@Inject(LocaleService) private readonly _localeService: LocaleService,@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,- @Inject(DocLayoutExecutorService) private readonly _docLayoutExecutorService: DocLayoutExecutorService+ @Inject(DocLayoutExecutorService) private readonly _docLayoutExecutorService: DocLayoutExecutorService,+ @IConfigService private readonly _configService: IConfigService) {super();@@ -153,7 +158,11 @@ export class DocSkeletonManagerService extends RxDisposable implements IRenderMo}private _buildSkeleton(documentViewModel: DocumentViewModel) {- return DocumentSkeleton.create(documentViewModel, this._localeService);+ const isSheetEditor = this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY ||+ this._context.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;+ return DocumentSkeleton.create(documentViewModel, this._localeService, {+ lineGap: isSheetEditor ? this._configService.getConfig<number>(SHEET_TEXT_LINE_GAP) : undefined,+ });}private _buildDocViewModel(documentDataModel: DocumentDataModel) {diff --git a/packages/engine-render/src/basics/interfaces.ts b/packages/engine-render/src/basics/interfaces.tsindex f68960301e..3a92977c58 100644--- a/packages/engine-render/src/basics/interfaces.ts+++ b/packages/engine-render/src/basics/interfaces.ts@@ -95,6 +95,7 @@ export interface IFontLocale {}export interface IDocsConfig extends IReferenceSource, IDocumentLayout {+ lineGap?: number;localeService: LocaleService;documentTextStyle?: IDocumentLayoutTextStyle;documentCompatibilityPolicy?: IDocumentCompatibilityPolicy;diff --git a/packages/engine-render/src/components/docs/layout/__tests__/doc-simple-skeleton.spec.ts b/packages/engine-render/src/components/docs/layout/__tests__/doc-simple-skeleton.spec.tsindex c198a3a453..d7a1bfa7a9 100644--- a/packages/engine-render/src/components/docs/layout/__tests__/doc-simple-skeleton.spec.ts+++ b/packages/engine-render/src/components/docs/layout/__tests__/doc-simple-skeleton.spec.ts@@ -14,7 +14,8 @@* limitations under the License.*/-import { beforeEach, describe, expect, it, vi } from 'vitest';+import { Injector } from '@univerjs/core';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { DocSimpleSkeleton } from '../doc-simple-skeleton';import { FontCache } from '../shaping-engine/font-cache';@@ -23,17 +24,33 @@ function measure(text: string) {width: text.length * 10,fontBoundingBoxAscent: 8,fontBoundingBoxDescent: 2,- } as any;+ actualBoundingBoxAscent: 8,+ actualBoundingBoxDescent: 2,+ };}describe('doc simple skeleton', () => {+ let injector: Injector;+beforeEach(() => {+ injector = new Injector();+ Reflect.set(FontCache, '_context', null);+ FontCache.invalidateMetrics(() => true);+ vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({+ font: '',+ measureText: vi.fn(measure),+ } as unknown as CanvasRenderingContext2D);+ });++ afterEach(() => {+ injector.dispose();vi.restoreAllMocks();- vi.spyOn(FontCache, 'getMeasureText').mockImplementation((text: string) => measure(text));+ Reflect.set(FontCache, '_context', null);+ FontCache.invalidateMetrics(() => true);});it('handles empty text and no-wrap text', () => {- const empty = new DocSimpleSkeleton('', '12px Arial', true, 100, 100);+ const empty = injector.createInstance(DocSimpleSkeleton, '', '12px Arial', true, 100, 100);const emptyLines = empty.calculate();expect(emptyLines).toEqual([{@@ -46,7 +63,7 @@ describe('doc simple skeleton', () => {expect(empty.getTotalHeight()).toBe(10);expect(empty.getTotalWidth()).toBe(0);- const noWrap = new DocSimpleSkeleton('hello world', '12px Arial', false, 30, 200);+ const noWrap = injector.createInstance(DocSimpleSkeleton, 'hello world', '12px Arial', false, 30, 200);const lines = noWrap.calculate();expect(lines).toHaveLength(1);expect(lines[0].text).toBe('hello world');@@ -56,43 +73,38 @@ describe('doc simple skeleton', () => {});it('wraps long text and uses cache behavior', () => {- const skeleton = new DocSimpleSkeleton('supercalifragilistic', '12px Arial', true, 25, 100);+ const skeleton = injector.createInstance(DocSimpleSkeleton, 'supercalifragilistic', '12px Arial', true, 25, 100);const lines = skeleton.calculate();expect(lines.length).toBeGreaterThan(1);expect(lines.every((line) => line.width > 0)).toBe(true);expect(lines.every((line) => line.width <= 25 || line.text.length === 1)).toBe(true);- const callCountAfterFirst = (FontCache.getMeasureText as any).mock.calls.length;const second = skeleton.calculate();expect(second).toBe(lines);- expect((FontCache.getMeasureText as any).mock.calls.length).toBe(callCountAfterFirst);});it('recalculates after makeDirty in no-wrap mode', () => {- const skeleton = new DocSimpleSkeleton('hello world', '12px Arial', false, 30, 200);+ const skeleton = injector.createInstance(DocSimpleSkeleton, 'hello world', '12px Arial', false, 30, 200);const first = skeleton.calculate();- const callCountAfterFirst = (FontCache.getMeasureText as any).mock.calls.length;const second = skeleton.calculate();expect(second).toBe(first);- expect((FontCache.getMeasureText as any).mock.calls.length).toBe(callCountAfterFirst);skeleton.makeDirty();const third = skeleton.calculate();expect(third).not.toBe(first);expect(third).toHaveLength(1);expect(third[0].text).toBe('hello world');- expect((FontCache.getMeasureText as any).mock.calls.length).toBeGreaterThan(callCountAfterFirst);});it('respects height limits when wrapping', () => {- const skeleton = new DocSimpleSkeleton('a b c d e f g h i j k', '12px Arial', true, 20, 15);+ const skeleton = injector.createInstance(DocSimpleSkeleton, 'a b c d e f g h i j k', '12px Arial', true, 20, 15);const lines = skeleton.calculate();- expect(lines.length).toBeGreaterThan(0);- expect(skeleton.getTotalHeight()).toBeGreaterThanOrEqual(10);+ expect(lines.slice(0, 2).map((line) => line.text)).toEqual(['a ', 'b ']);+ expect(lines.some((line) => line.text.includes('c'))).toBe(false);});it('content with \n', () => {- const skeleton = new DocSimpleSkeleton('客户经理UM1\n客户经理UM2', '11pt Arial', true, 60, Infinity);+ const skeleton = injector.createInstance(DocSimpleSkeleton, '客户经理UM1\n客户经理UM2', '11pt Arial', true, 60, Infinity);const lines = skeleton.calculate();expect(lines.length).toBe(4);expect(lines[0].text).toBe('客户经理');@@ -100,4 +112,16 @@ describe('doc simple skeleton', () => {expect(lines[2].text).toBe('客户经理');expect(lines[3].text).toBe('UM2');});++ it('adds the configured gap only between wrapped lines without changing glyph metrics or breaks', () => {+ const baseline = injector.createInstance(DocSimpleSkeleton, 'first\nsecond\nthird', '12px Arial', true, 100, Infinity);+ const spaced = injector.createInstance(DocSimpleSkeleton, 'first\nsecond\nthird', '12px Arial', true, 100, Infinity, 2);+ expect(spaced.calculate()).toEqual(baseline.calculate());+ expect(spaced.getTotalHeight()).toBe(baseline.getTotalHeight() + 4);+ expect(spaced.getTotalWidth()).toBe(baseline.getTotalWidth());++ const single = injector.createInstance(DocSimpleSkeleton, 'first', '12px Arial', true, 100, Infinity, 2);+ single.calculate();+ expect(single.getTotalHeight()).toBe(baseline.getLines()[0].height);+ });});diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.tsindex 676655461d..fa3330377b 100644--- a/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/layout-ruler.ts@@ -1490,6 +1490,10 @@ function _getParagraphLineMetrics(drawingMLLineHeight);+ if (preLine) {+ marginTop += sectionBreakConfig.lineGap ?? 0;+ }+if (startingSection && marginTop > 0 && isTraditionalDocumentCompatibility(paragraphConfig.documentCompatibilityPolicy)) {marginTop = _collapseSectionBeforeSpacing(ctx, startingSection.children[0].startIndex - 2, marginTop);}diff --git a/packages/engine-render/src/components/docs/layout/doc-simple-skeleton.ts b/packages/engine-render/src/components/docs/layout/doc-simple-skeleton.tsindex 46415a02a8..7d5799a08f 100644--- a/packages/engine-render/src/components/docs/layout/doc-simple-skeleton.ts+++ b/packages/engine-render/src/components/docs/layout/doc-simple-skeleton.ts@@ -36,7 +36,8 @@ export class DocSimpleSkeleton {private _fontStyle: string,private _warp: boolean,private _width: number,- private _height: number+ private _height: number,+ private _lineGap = 0) {this._lineBreaker = new LineBreaker(this._text);}@@ -97,7 +98,7 @@ export class DocSimpleSkeleton {// Push current line if it has contentif (currentLine.text.length > 0) {this._lines.push(currentLine);- totalHeight += currentLine.height;+ totalHeight += currentLine.height + (this._lines.length > 1 ? this._lineGap : 0);if (totalHeight > this._height) {break;}@@ -187,7 +188,7 @@ export class DocSimpleSkeleton {// If there's remaining text, need to wrap to next lineif (remainingText.length > 0) {this._lines.push(currentLine);- totalHeight += currentLine.height;+ totalHeight += currentLine.height + (this._lines.length > 1 ? this._lineGap : 0);if (totalHeight > this._height) {break;}@@ -208,7 +209,7 @@ export class DocSimpleSkeleton {if (currentLine.text.length > 0) {// Push the current line firstthis._lines.push(currentLine);- totalHeight += currentLine.height;+ totalHeight += currentLine.height + (this._lines.length > 1 ? this._lineGap : 0);if (totalHeight > this._height) {break;}@@ -241,7 +242,7 @@ export class DocSimpleSkeleton {// For excel, when cell text is wrapped, \n should be treated as mandatory line break, so we need to break the line here.if (isMandatoryBreak) {this._lines.push(currentLine);- totalHeight += currentLine.height;+ totalHeight += currentLine.height + (this._lines.length > 1 ? this._lineGap : 0);if (totalHeight > this._height) {break;@@ -272,7 +273,7 @@ export class DocSimpleSkeleton {}getTotalHeight() {- return this._lines.reduce((acc, line) => acc + line.height, 0);+ return this._lines.reduce((acc, line) => acc + line.height, 0) + Math.max(0, this._lines.length - 1) * this._lineGap;}getTotalWidth() {diff --git a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts b/packages/engine-render/src/components/docs/layout/doc-skeleton.tsindex 4f6a5aa43f..c1d5af44b7 100644--- a/packages/engine-render/src/components/docs/layout/doc-skeleton.ts+++ b/packages/engine-render/src/components/docs/layout/doc-skeleton.ts@@ -93,7 +93,6 @@ import {cachePrecomputedSlicedTableSkeletons,cachePrecomputedTableSkeleton,getTableIdAndSliceIndex,-startTableSkeletonBuild,startTableSkeletonsBuild,stepTableSkeletonBuild,@@ -119,7 +118,6 @@ import {getLastPage,getNullSkeleton,getPageFromPath,-prepareSectionBreakConfig,resetContext,setPageParent,@@ -859,9 +857,7 @@ export interface IFindNodeRestrictions {function getPagePath(page: IDocumentSkeletonPage) {const path: (string | number)[] = [];- // eslint-disable-next-line ts/no-explicit-anylet skeNode: any = page;- // eslint-disable-next-line ts/no-explicit-anylet parent: any = skeNode.parent;while (parent) {if (parent.page === skeNode && parent.noteId && parent.parent?.notes) {@@ -1242,19 +1238,22 @@ export class DocumentSkeleton extends Skeleton {private _modernHorizontalMargin: number | undefined;+ private readonly _lineGap: number;+constructor(private _docViewModel: DocumentViewModel,localeService: LocaleService,- options: { isolateIncrementalPublications?: boolean } = {}+ options: { isolateIncrementalPublications?: boolean; lineGap?: number } = {}) {super(localeService);this._isolateIncrementalPublications = options.isolateIncrementalPublications !== false;+ this._lineGap = options.lineGap ?? 0;}static create(docViewModel: DocumentViewModel,localeService: LocaleService,- options?: { isolateIncrementalPublications?: boolean }+ options?: { isolateIncrementalPublications?: boolean; lineGap?: number }) {return new DocumentSkeleton(docViewModel, localeService, options);}@@ -5149,6 +5148,7 @@ export class DocumentSkeleton extends Skeleton {} = documentStyle;const docsConfig: IDocsConfig = {+ lineGap: this._lineGap,headerTreeMap,footerTreeMap,lists,diff --git a/packages/engine-render/src/components/sheets/__tests__/sheet.render-skeleton.spec.ts b/packages/engine-render/src/components/sheets/__tests__/sheet.render-skeleton.spec.tsindex 8ebcc2a9d0..a2cfeabc89 100644--- a/packages/engine-render/src/components/sheets/__tests__/sheet.render-skeleton.spec.ts+++ b/packages/engine-render/src/components/sheets/__tests__/sheet.render-skeleton.spec.ts@@ -20,8 +20,10 @@ import {DataStreamTreeTokenType,DocumentFlavor,HorizontalAlign,+ IConfigService,LocaleType,RANGE_TYPE,+ SHEET_TEXT_LINE_GAP,Tools,Univer,UniverInstanceType,@@ -322,3 +324,75 @@ describe('Custom number display', () => {expect(getCustomNumberDisplayText('10/1/2022', '13.33px SimSun', 70)).toBe('10/1/2022');});});++describe('Configured cell text line gap', () => {+ it.each([false, true])('keeps saved cells intact and includes inter-line gaps in auto height (rich: %s)', (rich) => {+ const environment = setupRenderTestEnv();+ const univer = new Univer({ locale: LocaleType.EN_US });+ const injector = univer.__getInjector();+ const workbook = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, {+ id: 'line-gap',+ sheetOrder: ['sheet'],+ sheets: {+ sheet: {+ id: 'sheet',+ rowCount: 10,+ columnCount: 10,+ defaultColumnWidth: 200,+ rowData: { 0: { h: 30 }, 1: { h: 15 } },+ cellData: {+ 0: {+ 0: {+ v: 'one\ntwo\nthree',+ s: { fs: 12, tb: WrapStrategy.WRAP },+ ...(rich+ ? {+ p: {+ id: 'rich-lines',+ documentStyle: {},+ body: {+ dataStream: 'one\rtwo\rthree\r\n',+ paragraphs: [{ startIndex: 3, paragraphId: 'one' }, { startIndex: 7, paragraphId: 'two' }, { startIndex: 13, paragraphId: 'three' }],+ sectionBreaks: [{ startIndex: 14, sectionId: 'section' }],+ },+ },+ }+ : {}),+ },+ },+ 1: { 0: { v: 'one', s: { fs: 12, tb: WrapStrategy.WRAP } } },+ },+ },+ },+ });+ const worksheet = workbook.getActiveSheet()!;+ const baseline = injector.createInstance(SpreadsheetSkeleton, worksheet, workbook.getStyles());+ injector.get(IConfigService).setConfig(SHEET_TEXT_LINE_GAP, 2);+ const spaced = injector.createInstance(SpreadsheetSkeleton, worksheet, workbook.getStyles());+ try {+ baseline.calculate();+ spaced.calculate();+ const saved = Tools.deepClone(workbook.getSnapshot());+ expect(spaced.calculateAutoHeightForCell(0, 0)).toBeCloseTo(baseline.calculateAutoHeightForCell(0, 0)! + 4);+ expect(spaced.calculateAutoHeightForCell(1, 0)).toBe(baseline.calculateAutoHeightForCell(1, 0));+ expect(worksheet.getRowHeight(0)).toBe(30);+ if (rich) {+ const cell = worksheet.getCellRaw(0, 0)!;+ baseline._setFontStylesCache(0, 0, cell, {}, false);+ spaced._setFontStylesCache(0, 0, cell, {}, false);+ const oldLines = baseline.stylesCache.fontMatrix.getValue(0, 0)!.documentSkeleton!.getSkeletonData()!.pages[0].sections[0].columns[0].lines;+ const newLines = spaced.stylesCache.fontMatrix.getValue(0, 0)!.documentSkeleton!.getSkeletonData()!.pages[0].sections[0].columns[0].lines;+ expect(newLines).toHaveLength(oldLines.length);+ newLines.forEach((line, index) => {+ expect(line.top + line.marginTop - oldLines[index].top - oldLines[index].marginTop).toBeCloseTo(index * 2);+ });+ }+ expect(workbook.getSnapshot()).toEqual(saved);+ } finally {+ baseline.dispose();+ spaced.dispose();+ univer.dispose();+ environment.restore();+ }+ });+});diff --git a/packages/engine-render/src/components/sheets/extensions/__tests__/font.spec.ts b/packages/engine-render/src/components/sheets/extensions/__tests__/font.spec.tsindex cb59951590..98dd310954 100644--- a/packages/engine-render/src/components/sheets/extensions/__tests__/font.spec.ts+++ b/packages/engine-render/src/components/sheets/extensions/__tests__/font.spec.ts@@ -223,6 +223,7 @@ describe('font extension', () => {startY: 0,endX: 100,endY: 20,+ spreadsheetSkeleton: { textLineGap: 4 },fontCache: createFontCache({horizontalAlign: HorizontalAlign.UNSPECIFIED,verticalAlign: VerticalAlign.MIDDLE,@@ -231,12 +232,13 @@ describe('font extension', () => {cellData: { v: 123, t: CellValueType.NUMBER },}),} as any;- font._renderText(ctx, 0, 0, renderFontCtx, overflow);+ font._renderText(ctx, renderFontCtx);expect(drawWithSpy).toHaveBeenLastCalledWith(ctx,expect.objectContaining({hAlign: HorizontalAlign.RIGHT,warp: true,+ lineGap: 4,}));@@ -245,7 +247,7 @@ describe('font extension', () => {wrapStrategy: WrapStrategy.OVERFLOW,cellData: { v: true, t: CellValueType.BOOLEAN },});- font._renderText(ctx, 0, 0, renderFontCtx, overflow);+ font._renderText(ctx, renderFontCtx);expect(drawPlainSpy).toHaveBeenLastCalledWith(ctx,expect.objectContaining({@@ -262,7 +264,7 @@ describe('font extension', () => {wrapStrategy: WrapStrategy.OVERFLOW,cellData: { v: 123, t: CellValueType.NUMBER },});- font._renderText(ctx, 0, 0, renderFontCtx, overflow);+ font._renderText(ctx, renderFontCtx);expect(drawPlainSpy).toHaveBeenLastCalledWith(ctx,expect.objectContaining({@@ -277,7 +279,7 @@ describe('font extension', () => {renderFontCtx.fontCache = createFontCache({cellData: { v: null, t: CellValueType.STRING },});- font._renderText(ctx, 0, 0, renderFontCtx, overflow);+ font._renderText(ctx, renderFontCtx);expect(drawWithSpy.mock.calls.length).toBe(before);expect(drawPlainSpy.mock.calls.length).toBe(beforePlain);});diff --git a/packages/engine-render/src/components/sheets/extensions/font.ts b/packages/engine-render/src/components/sheets/extensions/font.tsindex e4825f6652..59ff5209fc 100644--- a/packages/engine-render/src/components/sheets/extensions/font.ts+++ b/packages/engine-render/src/components/sheets/extensions/font.ts@@ -14,9 +14,6 @@* limitations under the License.*/-/* eslint-disable max-lines-per-function */-/* eslint-disable complexity */-import type {ICellDataForSheetInterceptor,ICellWithCoord,@@ -27,7 +24,7 @@ import type {Nullable,ObjectMatrix,} from '@univerjs/core';-import type { IBoundRectNoAngle, IViewportInfo } from '../../../basics';+import type { IBoundRectNoAngle, IViewportInfo } from '../../../basics/vector2';import type { UniverRenderingContext } from '../../../context';import type { Documents } from '../../docs/document';import type { IDrawInfo } from '../../extension';@@ -41,7 +38,7 @@ import {Tools,WrapStrategy,} from '@univerjs/core';-import { FIX_ONE_PIXEL_BLUR_OFFSET } from '../../../basics';+import { FIX_ONE_PIXEL_BLUR_OFFSET } from '../../../basics/const';import { VERTICAL_ROTATE_ANGLE } from '../../../basics/text-rotation';import { clampRange, inViewRanges } from '../../../basics/tools';import { Text } from '../../../shape/text';@@ -389,7 +386,7 @@ export class Font extends SheetExtension {if (fontCache.documentSkeleton) {this._renderDocuments(ctx, row, col, renderFontCtx, spreadsheetSkeleton.overflowCache);} else {- this._renderText(ctx, row, col, renderFontCtx, spreadsheetSkeleton.overflowCache);+ this._renderText(ctx, renderFontCtx);}ctx.restore();@@ -509,7 +506,7 @@ export class Font extends SheetExtension {} else {try {ctx.drawImage(image, -rotatedWidth / 2, -rotatedHeight / 2, width, height);- } catch (e) {+ } catch {this._drawFallbackImage(ctx, -rotatedWidth / 2, -rotatedHeight / 2, width, height);}}@@ -524,7 +521,7 @@ export class Font extends SheetExtension {* @param renderFontContext* @param row* @param col- * @param fontCache+ * @param padding*/private _clipByRenderBounds(renderFontContext: IRenderFontContext, row: number, col: number, padding = 0) {const { ctx, scale, overflowRectangle, fontCache } = renderFontContext;@@ -624,10 +621,7 @@ export class Font extends SheetExtension {private _renderText(ctx: UniverRenderingContext,- row: number,- col: number,- renderFontCtx: IRenderFontContext,- overflowCache: ObjectMatrix<IRange>+ renderFontCtx: IRenderFontContext) {const { fontCache } = renderFontCtx;if (!fontCache) return;@@ -648,6 +642,7 @@ export class Font extends SheetExtension {text,fontStyle: fontCache.fontString,warp: wrapStrategy === WrapStrategy.WRAP && vertexAngle === 0,+ lineGap: renderFontCtx.spreadsheetSkeleton.textLineGap,hAlign,vAlign: fontCache.verticalAlign,width: cellWidth,diff --git a/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts b/packages/engine-render/src/components/sheets/sheet.render-skeleton.tsindex 939462b371..2f688d8f93 100644--- a/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts+++ b/packages/engine-render/src/components/sheets/sheet.render-skeleton.ts@@ -14,7 +14,26 @@* limitations under the License.*/-import type { BorderStyleTypes, IBorderStyleData, ICellDataForSheetInterceptor, ICellInfo, ICellWithCoord, IColAutoWidthInfo, IColumnRange, IDocumentData, IPaddingData, IRange, IRowAutoHeightInfo, IRowRange, ISize, IStyleData, ITextRotation, Nullable, Styles, Worksheet } from '@univerjs/core';+import type {+ BorderStyleTypes,+ IBorderStyleData,+ ICellDataForSheetInterceptor,+ ICellInfo,+ ICellWithCoord,+ IColAutoWidthInfo,+ IColumnRange,+ IDocumentData,+ IPaddingData,+ IRange,+ IRowAutoHeightInfo,+ IRowRange,+ ISize,+ IStyleData,+ ITextRotation,+ Nullable,+ Styles,+ Worksheet,+} from '@univerjs/core';import type { IDocumentSkeletonColumn } from '../../basics/i-document-skeleton-cached';import type { ITransformChangeState } from '../../basics/interfaces';import type { IBoundRectNoAngle, IPoint, IViewportInfo } from '../../basics/vector2';@@ -22,7 +41,6 @@ import type { Scene } from '../../scene';import type { IBorderCache, IFontCacheItem, IStylesCache } from './interfaces';import {BooleanNumber,-CellValueType,ColorKit,DEFAULT_STYLES,@@ -30,45 +48,42 @@ import {getColorStyle,getDisplayValueFromCell,HorizontalAlign,-IConfigService,IContextService,-Inject,Injector,-isCellCoverable,isDefaultFormat,-isNullCell,-isWhiteColor,-LocaleService,-numfmt,ObjectMatrix,Range,searchArray,+ SHEET_TEXT_LINE_GAP,SheetSkeleton,-ThemeService,Tools,VerticalAlign,-WrapStrategy,} from '@univerjs/core';import { distinctUntilChanged, startWith } from 'rxjs';-import { FontCache } from '../../basics';import { BORDER_TYPE, COLOR_BLACK_RGB, MAXIMUM_COL_WIDTH, MAXIMUM_ROW_HEIGHT, MIN_COL_WIDTH } from '../../basics/const';import { getRotateOffsetAndFarthestHypotenuse } from '../../basics/draw';import { convertTextRotation, VERTICAL_ROTATE_ANGLE } from '../../basics/text-rotation';import { degToRad, getFontStyleString } from '../../basics/tools';import { DocSimpleSkeleton } from '../docs/layout/doc-simple-skeleton';import { DocumentSkeleton } from '../docs/layout/doc-skeleton';+import { FontCache } from '../docs/layout/shaping-engine/font-cache';import { columnIterator } from '../docs/layout/tools';import { DocumentViewModel } from '../docs/view-model/document-view-model';-import { EXPAND_SIZE_FOR_RENDER_OVERFLOW, MEASURE_EXTENT, MEASURE_EXTENT_FOR_PARAGRAPH, shouldRenderRowText } from './constants';+import {+ EXPAND_SIZE_FOR_RENDER_OVERFLOW,+ MEASURE_EXTENT,+ MEASURE_EXTENT_FOR_PARAGRAPH,+ shouldRenderRowText,+} from './constants';import { SHEET_VIEWPORT_KEY } from './interfaces';interface IRowColumnRange extends IRowRange, IColumnRange { }@@ -310,6 +325,8 @@ export class SpreadsheetSkeleton extends SheetSkeleton {private _defaultGridlinesColor!: string;private _scene: Nullable<Scene> = null;+ readonly textLineGap: number;+constructor(worksheet: Worksheet,_styles: Styles,@@ -319,6 +336,7 @@ export class SpreadsheetSkeleton extends SheetSkeleton {@Inject(Injector) _injector: Injector) {super(worksheet, _styles, _localeService, _contextService, _configService, _injector);+ this.textLineGap = _configService.getConfig<number>(SHEET_TEXT_LINE_GAP) ?? 0;const themeService = _injector.get(ThemeService);this.disposeWithMe(themeService.currentTheme$.subscribe(() => {const gray200 = themeService.getColorFromTheme('gray.200');@@ -503,7 +521,6 @@ export class SpreadsheetSkeleton extends SheetSkeleton {* @param vpInfo viewBounds* @param options screen scale*/- // eslint-disable-next-line max-lines-per-function, complexitysetStylesCache(vpInfo?: IViewportInfo, options?: ISetStylesCacheOptions): Nullable<SpreadsheetSkeleton> {if (!this._worksheetData) return;if (!this.rowHeightAccumulation || !this.columnWidthAccumulation) return;@@ -716,7 +733,6 @@ export class SpreadsheetSkeleton extends SheetSkeleton {return results;}- // eslint-disable-next-line max-lines-per-function, complexitycalculateAutoHeightForCell(row: number, col: number) {const { columnData, defaultColumnWidth } = this._worksheetData;const cellMergeInfo = this.worksheet.getCellInfoInMergeData(row, col);@@ -775,7 +791,7 @@ export class SpreadsheetSkeleton extends SheetSkeleton {documentModel.updateDocumentDataPageSize(colWidth);}- const documentSkeleton = DocumentSkeleton.create(documentViewModel, this._localeService);+ const documentSkeleton = DocumentSkeleton.create(documentViewModel, this._localeService, { lineGap: this.textLineGap });documentSkeleton.calculate();let { height: h = 0 } = getDocsSkeletonPageSize(documentSkeleton, angle) ?? {};@@ -816,7 +832,8 @@ export class SpreadsheetSkeleton extends SheetSkeleton {getFontStyleString(style).fontCache,style?.tb === WrapStrategy.WRAP,colWidth - paddingLeft - paddingRight,- Infinity+ Infinity,+ this.textLineGap);skeleton.calculate();return skeleton.getTotalHeight() + paddingTop + paddingBottom;@@ -1005,7 +1022,7 @@ export class SpreadsheetSkeleton extends SheetSkeleton {documentModel.updateDocumentDataPageSize(Infinity, Infinity);}- const documentSkeleton = DocumentSkeleton.create(documentViewModel, this._localeService);+ const documentSkeleton = DocumentSkeleton.create(documentViewModel, this._localeService, { lineGap: this.textLineGap });documentSkeleton.calculate();// key@@ -1121,7 +1138,6 @@ export class SpreadsheetSkeleton extends SheetSkeleton {* the text content of this cell can be drawn to both sides, not limited by the cell's width.* Overflow on the left or right is aligned according to the text's horizontal alignment.*/- // eslint-disable-next-line complexity, max-lines-per-functionprivate _calculateOverflowCell(row: number, column: number, docsConfig: IFontCacheItem, hasMergeData = true): boolean {// wrap and angle handlerconst { documentSkeleton, vertexAngle = 0, centerAngle = 0, horizontalAlign, wrapStrategy } = docsConfig;@@ -1453,7 +1469,7 @@ export class SpreadsheetSkeleton extends SheetSkeleton {if (fontCache.documentSkeleton) {const snapshot = fontCache.documentSkeleton.getViewModel().getDataModel().getSnapshot();const documentModel = new DocumentDataModel(scaleDocumentDataForShrinkToFit(snapshot, scale, fallbackFontSize));- const documentSkeleton = DocumentSkeleton.create(new DocumentViewModel(documentModel), this._localeService);+ const documentSkeleton = DocumentSkeleton.create(new DocumentViewModel(documentModel), this._localeService, { lineGap: this.textLineGap });documentSkeleton.calculate();fontCache.documentSkeleton = documentSkeleton;} else {@@ -1533,7 +1549,7 @@ export class SpreadsheetSkeleton extends SheetSkeleton {}const documentViewModel = new DocumentViewModel(documentModel);if (documentViewModel) {- const documentSkeleton = DocumentSkeleton.create(documentViewModel, this._localeService);+ const documentSkeleton = DocumentSkeleton.create(documentViewModel, this._localeService, { lineGap: this.textLineGap });documentSkeleton.calculate();config = {diff --git a/packages/engine-render/src/shape/__tests__/text.spec.ts b/packages/engine-render/src/shape/__tests__/text.spec.tsindex be4c6a657d..cc12f90f82 100644--- a/packages/engine-render/src/shape/__tests__/text.spec.ts+++ b/packages/engine-render/src/shape/__tests__/text.spec.ts@@ -14,8 +14,11 @@* limitations under the License.*/-import { CellValueType, HorizontalAlign, TextDecoration, VerticalAlign } from '@univerjs/core';-import { describe, expect, it, vi } from 'vitest';+import type { UniverRenderingContext } from '../../context';+import { CellValueType, HorizontalAlign, Injector, TextDecoration, VerticalAlign } from '@univerjs/core';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { DocSimpleSkeleton } from '../../components/docs/layout/doc-simple-skeleton';+import { FontCache } from '../../components/docs/layout/shaping-engine/font-cache';import { Text } from '../text';function createCtx() {@@ -33,24 +36,41 @@ function createCtx() {fillStyle: '',strokeStyle: '',lineWidth: 1,- } as any;-}--function createSkeleton(lines: Array<{ text: string; width: number; height: number; baseline: number }>) {- const totalHeight = lines.reduce((sum, item) => sum + item.height, 0);- return {- calculate: vi.fn(() => lines),- getTotalHeight: vi.fn(() => totalHeight),- } as any;+ };}describe('text shape', () => {+ let injector: Injector;++ beforeEach(() => {+ injector = new Injector();+ Reflect.set(FontCache, '_context', null);+ FontCache.invalidateMetrics(() => true);+ vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({+ font: '',+ measureText: (text: string) => ({+ width: text.length * 5,+ fontBoundingBoxAscent: 8,+ fontBoundingBoxDescent: 2,+ actualBoundingBoxAscent: 8,+ actualBoundingBoxDescent: 2,+ }),+ } as unknown as CanvasRenderingContext2D);+ });++ afterEach(() => {+ injector.dispose();+ vi.restoreAllMocks();+ Reflect.set(FontCache, '_context', null);+ FontCache.invalidateMetrics(() => true);+ });+it('draws center/right alignment', () => {const ctx = createCtx();- const skeleton = createSkeleton([{ text: 'abcd', width: 20, height: 10, baseline: 8 }]);+ const skeleton = injector.createInstance(DocSimpleSkeleton, 'abcd', '12px Arial', false, 100, Infinity);Text.drawWith(- ctx,+ ctx as unknown as UniverRenderingContext,{text: 'abcd',fontStyle: '12px Arial',@@ -58,13 +78,13 @@ describe('text shape', () => {height: 30,hAlign: HorizontalAlign.CENTER,vAlign: VerticalAlign.TOP,- } as any,+ },skeleton);expect(ctx.fillText).toHaveBeenCalledWith('abcd', 40, 8);Text.drawWith(- ctx,+ ctx as unknown as UniverRenderingContext,{text: 'abcd',fontStyle: '12px Arial',@@ -72,7 +92,7 @@ describe('text shape', () => {height: 30,hAlign: HorizontalAlign.RIGHT,vAlign: VerticalAlign.TOP,- } as any,+ },skeleton);expect(ctx.fillText).toHaveBeenLastCalledWith('abcd', 80, 8);@@ -80,10 +100,10 @@ describe('text shape', () => {it('keeps number left-aligned when overflow in no-wrap mode', () => {const ctx = createCtx();- const skeleton = createSkeleton([{ text: '123456', width: 60, height: 10, baseline: 8 }]);+ const skeleton = injector.createInstance(DocSimpleSkeleton, '123456', '12px Arial', false, 100, Infinity);Text.drawWith(- ctx,+ ctx as unknown as UniverRenderingContext,{text: '123456',fontStyle: '12px Arial',@@ -93,7 +113,7 @@ describe('text shape', () => {hAlign: HorizontalAlign.RIGHT,vAlign: VerticalAlign.TOP,cellValueType: CellValueType.NUMBER,- } as any,+ },skeleton);@@ -103,7 +123,7 @@ describe('text shape', () => {it('builds skeleton internally and supports middle/bottom vertical alignment', () => {const middleCtx = createCtx();const middleHeight = Text.drawWith(- middleCtx,+ middleCtx as unknown as UniverRenderingContext,{text: 'line',fontStyle: '12px Arial',@@ -112,14 +132,14 @@ describe('text shape', () => {warp: false,hAlign: HorizontalAlign.LEFT,vAlign: VerticalAlign.MIDDLE,- } as any+ });expect(middleHeight).toBeGreaterThanOrEqual(0);expect(middleCtx.fillText).toHaveBeenCalledTimes(1);const bottomCtx = createCtx();const bottomHeight = Text.drawWith(- bottomCtx,+ bottomCtx as unknown as UniverRenderingContext,{text: 'line',fontStyle: '12px Arial',@@ -130,52 +150,16 @@ describe('text shape', () => {vAlign: VerticalAlign.BOTTOM,underline: true,strokeLine: true,- } as any+ });expect(bottomHeight).toBeGreaterThanOrEqual(0);expect(bottomCtx.beginPath).toHaveBeenCalled();});- it('reuses simple text layouts for non-wrapped text', () => {- const cache = (Text as any)._layoutCache as Map<string, unknown>;- cache.clear();- const firstCtx = createCtx();- const secondCtx = createCtx();-- Text.drawWith(- firstCtx,- {- text: 'repeat',- fontStyle: '12px Arial',- width: 100,- height: 20,- warp: false,- hAlign: HorizontalAlign.LEFT,- vAlign: VerticalAlign.TOP,- } as any- );- Text.drawWith(- secondCtx,- {- text: 'repeat',- fontStyle: '12px Arial',- width: 100,- height: 20,- warp: false,- hAlign: HorizontalAlign.LEFT,- vAlign: VerticalAlign.TOP,- } as any- );-- expect(cache.size).toBe(1);- expect(firstCtx.fillText).toHaveBeenCalledTimes(1);- expect(secondCtx.fillText).toHaveBeenCalledTimes(1);- });-it('draws plain cached text without nested context save and restore', () => {const ctx = createCtx();const height = Text.drawPlainWith(- ctx,+ ctx as unknown as UniverRenderingContext,{text: '123',fontStyle: '12px Arial',@@ -184,7 +168,7 @@ describe('text shape', () => {hAlign: HorizontalAlign.RIGHT,vAlign: VerticalAlign.TOP,cellValueType: CellValueType.NUMBER,- } as any+ });expect(height).toBeGreaterThanOrEqual(0);@@ -195,10 +179,10 @@ describe('text shape', () => {it('draws underline and strike line decorations', () => {const ctx = createCtx();- const skeleton = createSkeleton([{ text: 'abc', width: 6, height: 10, baseline: 8 }]);+ const skeleton = injector.createInstance(DocSimpleSkeleton, 'abc', '12px Arial', false, 100, Infinity);Text.drawWith(- ctx,+ ctx as unknown as UniverRenderingContext,{text: 'abc',fontStyle: '12px Arial',@@ -210,7 +194,7 @@ describe('text shape', () => {underlineType: TextDecoration.WAVY_DOUBLE,strokeLine: true,color: '#f00',- } as any,+ },skeleton);@@ -235,9 +219,9 @@ describe('text shape', () => {for (const { style, expectedLineWidth, expectedDash } of styleCases) {const ctx = createCtx();- const skeleton = createSkeleton([{ text: 'abc', width: 8, height: 10, baseline: 8 }]);+ const skeleton = injector.createInstance(DocSimpleSkeleton, 'abc', '12px Arial', false, 100, Infinity);Text.drawWith(- ctx,+ ctx as unknown as UniverRenderingContext,{text: 'abc',fontStyle: '12px Arial',@@ -247,7 +231,7 @@ describe('text shape', () => {vAlign: VerticalAlign.TOP,underline: true,underlineType: style,- } as any,+ },skeleton);@@ -258,39 +242,16 @@ describe('text shape', () => {}});- it('covers line type setup and line drawing helpers', () => {- const ctx = createCtx();- const setLineType = (Text as any)._setLineType.bind(Text);-- setLineType(ctx, TextDecoration.SINGLE, 7);- expect(ctx.lineWidth).toBe(1);- expect(ctx.setLineDash).toHaveBeenLastCalledWith([0]);-- setLineType(ctx, TextDecoration.DOTTED_HEAVY, 7);- expect(ctx.lineWidth).toBe(2);- expect(ctx.setLineDash).toHaveBeenLastCalledWith([2]);-- setLineType(ctx, TextDecoration.DASH_LONG, 7);- expect(ctx.lineWidth).toBe(1);- expect(ctx.setLineDash).toHaveBeenLastCalledWith([6]);-- setLineType(ctx, TextDecoration.DASH_DOT_DOT_HEAVY, 7);- expect(ctx.lineWidth).toBe(2);- expect(ctx.setLineDash).toHaveBeenLastCalledWith([2, 2, 5, 2, 2]);-- setLineType(ctx, TextDecoration.WAVY_HEAVY, 7);- expect(ctx.lineWidth).toBe(2);-- setLineType(ctx, 999 as TextDecoration, 7);- expect(ctx.lineWidth).toBe(7);- expect(ctx.setLineDash).toHaveBeenLastCalledWith([0]);-- const drawLine = (Text as any)._drawLine.bind(Text);- drawLine(ctx, 2, 3, 4, TextDecoration.SINGLE);- expect(ctx.lineTo).toHaveBeenLastCalledWith(6, 3);-- const beforeWaveCalls = ctx.lineTo.mock.calls.length;- drawLine(ctx, 1, 5, 3, TextDecoration.WAVE);- expect(ctx.lineTo.mock.calls.length).toBeGreaterThan(beforeWaveCalls);+ it.each([VerticalAlign.TOP, VerticalAlign.MIDDLE, VerticalAlign.BOTTOM])('uses the configured gap for drawing and vertical alignment: %s', (vAlign) => {+ const props = { text: 'one\ntwo\nthree', fontStyle: '12px Arial', width: 100, height: 80, warp: true, vAlign };+ const oldContext = createCtx();+ const newContext = createCtx();+ const oldLayout = injector.createInstance(DocSimpleSkeleton, props.text, props.fontStyle, true, 100, Infinity);+ const newLayout = injector.createInstance(DocSimpleSkeleton, props.text, props.fontStyle, true, 100, Infinity, 2);+ const oldHeight = Text.drawWith(oldContext as unknown as UniverRenderingContext, props, oldLayout);+ const newHeight = Text.drawWith(newContext as unknown as UniverRenderingContext, { ...props, lineGap: 2 }, newLayout);+ expect(newHeight).toBe(oldHeight + 4);+ const offset = vAlign === VerticalAlign.TOP ? 0 : vAlign === VerticalAlign.MIDDLE ? -2 : -4;+ expect(newContext.fillText.mock.calls.map((call, index) => call[2] - oldContext.fillText.mock.calls[index][2])).toEqual([offset, offset + 2, offset + 4]);});});diff --git a/packages/engine-render/src/shape/text.ts b/packages/engine-render/src/shape/text.tsindex 0862f0edf1..8840eae857 100644--- a/packages/engine-render/src/shape/text.ts+++ b/packages/engine-render/src/shape/text.ts@@ -18,7 +18,7 @@ import type { Nullable } from '@univerjs/core';import type { UniverRenderingContext } from '../context';import type { IShapeProps } from './shape';import { CellValueType, HorizontalAlign, TextDecoration, VerticalAlign } from '@univerjs/core';-import { COLOR_BLACK_RGB } from '../basics';+import { COLOR_BLACK_RGB } from '../basics/const';import { DocSimpleSkeleton } from '../components/docs/layout/doc-simple-skeleton';import { Shape } from './shape';@@ -28,6 +28,7 @@ export interface ITextProps extends IShapeProps {text: string;fontStyle: string;warp?: boolean;+ lineGap?: number;hAlign?: HorizontalAlign;vAlign?: VerticalAlign;color?: Nullable<string>;@@ -37,7 +38,17 @@ export interface ITextProps extends IShapeProps {cellValueType?: Nullable<CellValueType>;}-export const TEXT_OBJECT_ARRAY = ['text', 'fontStyle', 'warp', 'hAlign', 'vAlign', 'width', 'height', 'color'];+export const TEXT_OBJECT_ARRAY = [+ 'text',+ 'fontStyle',+ 'warp',+ 'lineGap',+ 'hAlign',+ 'vAlign',+ 'width',+ 'height',+ 'color',+];export class Text extends Shape<ITextProps> {private static readonly _MAX_LAYOUT_CACHE_SIZE = 5000;@@ -49,6 +60,7 @@ export class Text extends Shape<ITextProps> {text: string;fontStyle: string;warp: boolean;+ lineGap: number;hAlign: HorizontalAlign;vAlign: VerticalAlign;skeleton: DocSimpleSkeleton;@@ -61,6 +73,7 @@ export class Text extends Shape<ITextProps> {this.text = props.text;this.fontStyle = props.fontStyle;this.warp = props.warp ?? false;+ this.lineGap = props.lineGap ?? 0;this.hAlign = props.hAlign ?? HorizontalAlign.LEFT;this.vAlign = props.vAlign ?? VerticalAlign.TOP;this.skeleton = new DocSimpleSkeleton(@@ -68,14 +81,15 @@ export class Text extends Shape<ITextProps> {props.fontStyle,Boolean(props.warp),props.width,- props.height+ props.height,+ this.lineGap);}static override drawWith(ctx: UniverRenderingContext, props: ITextProps, _skeleton?: DocSimpleSkeleton) {- const { text, fontStyle, warp, hAlign, vAlign, width, height, left = 0, top = 0, cellValueType } = props;+ const { text, fontStyle, warp, lineGap = 0, hAlign, vAlign, width, height, left = 0, top = 0, cellValueType } = props;const cachedLayout = !_skeleton && !warp ? Text._getCachedLayout(text, fontStyle) : null;- const skeleton = cachedLayout ? null : _skeleton ?? new DocSimpleSkeleton(text, fontStyle, Boolean(warp), width, vAlign === VerticalAlign.TOP ? height : Infinity);+ const skeleton = cachedLayout ? null : _skeleton ?? new DocSimpleSkeleton(text, fontStyle, Boolean(warp), width, vAlign === VerticalAlign.TOP ? height : Infinity, lineGap);const lines = cachedLayout?.lines ?? skeleton!.calculate();const totalHeight = cachedLayout?.totalHeight ?? skeleton!.getTotalHeight();const offsetY = vAlign === VerticalAlign.TOP ? 0 : vAlign === VerticalAlign.MIDDLE ? (height - totalHeight) / 2 : height - totalHeight;@@ -141,7 +155,7 @@ export class Text extends Shape<ITextProps> {});}- lineTop = lineTop + lineHeight;+ lineTop = lineTop + lineHeight + lineGap;}ctx.restore();diff --git a/packages/sheets/src/config/config.ts b/packages/sheets/src/config/config.tsindex 7081a1015e..ae7973c9bb 100644--- a/packages/sheets/src/config/config.ts+++ b/packages/sheets/src/config/config.ts@@ -55,6 +55,15 @@ export interface IUniverSheetsConfig {*/autoHeightForMergedCells?: boolean;+ /**+ * Extra space in pixels between lines of cell text, including rich text and cell editors.+ * Applies at initialization to all workbooks in this Univer instance. Existing row heights+ * are unchanged until auto-resized; fixed-height cells may clip additional text.+ * Must be finite and non-negative.+ * @default 0+ */+ textLineGap?: number;+/*** Whether synchronize the frozen state to other users in real-time collaboration.* @default truediff --git a/packages/sheets/src/plugin.ts b/packages/sheets/src/plugin.tsindex f165b589aa..d2db228c3d 100644--- a/packages/sheets/src/plugin.ts+++ b/packages/sheets/src/plugin.ts@@ -16,7 +16,21 @@import type { Dependency } from '@univerjs/core';import type { IUniverSheetsConfig } from './config/config';-import { AUTO_HEIGHT_FOR_MERGED_CELLS, DependentOn, IConfigService, Inject, Injector, IS_ROW_STYLE_PRECEDE_COLUMN_STYLE, merge, mergeOverrideWithDependencies, Plugin, registerDependencies, touchDependencies, UniverInstanceType } from '@univerjs/core';+import {+ AUTO_HEIGHT_FOR_MERGED_CELLS,+ DependentOn,+ IConfigService,+ Inject,+ Injector,+ IS_ROW_STYLE_PRECEDE_COLUMN_STYLE,+ merge,+ mergeOverrideWithDependencies,+ Plugin,+ registerDependencies,+ SHEET_TEXT_LINE_GAP,+ touchDependencies,+ UniverInstanceType,+} from '@univerjs/core';import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';import pkg from '../package.json';import { defaultPluginConfig, SHEETS_PLUGIN_CONFIG_KEY } from './config/config';@@ -46,7 +60,13 @@ import { INumfmtService } from './services/numfmt/type';import { RangeProtectionRefRangeService } from './services/permission/range-permission/range-protection.ref-range';import { RangeProtectionService } from './services/permission/range-permission/range-protection.service';import { WorkbookPermissionService } from './services/permission/workbook-permission/workbook-permission.service';-import { WorksheetPermissionService, WorksheetProtectionPointModel, WorksheetProtectionRuleModel } from './services/permission/worksheet-permission';+import {+ WorksheetProtectionPointModel,+} from './services/permission/worksheet-permission/worksheet-permission-point.model';+import {+ WorksheetProtectionRuleModel,+} from './services/permission/worksheet-permission/worksheet-permission-rule.model';+import { WorksheetPermissionService } from './services/permission/worksheet-permission/worksheet-permission.service';import { SheetRangeThemeService } from './services/range-theme.service';import { RefRangeService } from './services/ref-range/ref-range.service';import { SheetsSelectionsService } from './services/selections/selection.service';@@ -80,6 +100,12 @@ export class UniverSheetsPlugin extends Plugin {}private _initConfig(): void {+ const textLineGap = this._config.textLineGap ?? 0;+ if (!Number.isFinite(textLineGap) || textLineGap < 0) {+ throw new RangeError('textLineGap must be a finite, non-negative number.');+ }+ this._configService.setConfig(SHEET_TEXT_LINE_GAP, textLineGap);+if (this._config?.onlyRegisterFormulaRelatedMutations) {this._configService.setConfig(ONLY_REGISTER_FORMULA_RELATED_MUTATIONS_KEY, true);}diff --git a/packages/sheets/src/services/permission/worksheet-permission/worksheet-permission.service.ts b/packages/sheets/src/services/permission/worksheet-permission/worksheet-permission.service.tsindex ea6f320cbe..d18c860786 100644--- a/packages/sheets/src/services/permission/worksheet-permission/worksheet-permission.service.ts+++ b/packages/sheets/src/services/permission/worksheet-permission/worksheet-permission.service.ts@@ -16,8 +16,16 @@import type { IPermissionPoint, Workbook, Worksheet } from '@univerjs/core';import type { IObjectModel, IObjectPointModel } from '../type';-import { ILogService, Inject, Injector, IPermissionService, IResourceManagerService, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';-+import {+ ILogService,+ Inject,+ Injector,+ IPermissionService,+ IResourceManagerService,+ IUniverInstanceService,+ RxDisposable,+ UniverInstanceType,+} from '@univerjs/core';import { takeUntil } from 'rxjs/operators';import { RangeProtectionRuleModel } from '../../../models/range-protection-rule.model';import { getAllRangePermissionPoint } from '../range-permission/util';diff --git a/packages/ui/src/__tests__/mobile-plugin.spec.ts b/packages/ui/src/__tests__/mobile-plugin.spec.tsdeleted file mode 100644index 2062a3efc0..0000000000--- a/packages/ui/src/__tests__/mobile-plugin.spec.ts+++ /dev/null@@ -1,44 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { ConfigService, ContextService, IConfigService, IContextService, Injector } from '@univerjs/core';-import { describe, expect, it } from 'vitest';-import { MOBILE_UI_MODE } from '../const';-import { UniverMobileUIPlugin } from '../mobile-plugin';--describe('UniverMobileUIPlugin', () => {- it('exposes mobile interaction mode to consumers without changing another runtime', () => {- const injector = new Injector([- [IConfigService, { useClass: ConfigService }],- [IContextService, { useClass: ContextService }],- [UniverMobileUIPlugin, {- useFactory: (injector: Injector) => injector.createInstance(UniverMobileUIPlugin, {}),- deps: [Injector],- }],- ]);- const peerInjector = new Injector([[IContextService, { useClass: ContextService }]]);- try {- const contextService = injector.get(IContextService);- expect(contextService.getContextValue(MOBILE_UI_MODE)).toBeFalsy();- injector.get(UniverMobileUIPlugin);- expect(contextService.getContextValue(MOBILE_UI_MODE)).toBe(true);- expect(peerInjector.get(IContextService).getContextValue(MOBILE_UI_MODE)).toBeFalsy();- } finally {- injector.dispose();- peerInjector.dispose();- }- });-});diff --git a/presets/packages/preset-sheets-core/src/preset.ts b/presets/packages/preset-sheets-core/src/preset.tsindex 8b25704e18..137ecc7a83 100644--- a/presets/packages/preset-sheets-core/src/preset.ts+++ b/presets/packages/preset-sheets-core/src/preset.ts@@ -136,6 +136,7 @@ export function UniverSheetsCorePreset(config: Partial<IUniverSheetsCorePresetCoonlyRegisterFormulaRelatedMutations: false,isRowStylePrecedeColumnStyle: sheets?.isRowStylePrecedeColumnStyle,autoHeightForMergedCells: sheets?.autoHeightForMergedCells,+ textLineGap: sheets?.textLineGap,freezeSync: sheets?.freezeSync,}],[UniverSheetsUIPlugin, {diff --git a/presets/packages/preset-sheets-core/src/types.ts b/presets/packages/preset-sheets-core/src/types.tsindex de6f5d7198..dd91116761 100644--- a/presets/packages/preset-sheets-core/src/types.ts+++ b/presets/packages/preset-sheets-core/src/types.ts@@ -36,7 +36,7 @@ export interface IUniverDocsPresetConfig extends}export interface IUniverSheetsPresetConfig extends- Pick<IUniverSheetsConfig, 'isRowStylePrecedeColumnStyle' | 'autoHeightForMergedCells' | 'freezeSync'>,+ Pick<IUniverSheetsConfig, 'isRowStylePrecedeColumnStyle' | 'autoHeightForMergedCells' | 'freezeSync' | 'textLineGap'>,Pick<IUniverSheetsUIConfig,'maxAutoHeightCount'