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(docs-ui): formula-editor can't scroll & edit link on cell editor (#3530)
zhangw6c4b96cf54f2
diff --git a/packages/core/src/docs/data-model/text-x/apply-utils/common.ts b/packages/core/src/docs/data-model/text-x/apply-utils/common.tsindex 07b6c9db05..fd35b57360 100644--- a/packages/core/src/docs/data-model/text-x/apply-utils/common.ts+++ b/packages/core/src/docs/data-model/text-x/apply-utils/common.ts@@ -14,9 +14,10 @@* limitations under the License.*/-import type { Nullable } from '../../../../shared';import { horizontalLineSegmentsSubtraction, sortRulesFactory, Tools } from '../../../../shared';import { isSameStyleTextRun } from '../../../../shared/compare';+import { DataStreamTreeTokenType } from '../../types';+import type { Nullable } from '../../../../shared';import type {ICustomBlock,ICustomDecoration,@@ -27,7 +28,6 @@ import type {ISectionBreak,ITextRun,} from '../../../../types/interfaces';-import { DataStreamTreeTokenType } from '../../types';export function normalizeTextRuns(textRuns: ITextRun[]) {const results: ITextRun[] = [];@@ -199,12 +199,11 @@ export function insertParagraphs(currentIndex: number) {const { paragraphs } = body;-if (paragraphs == null) {return;}- const { paragraphs: insertParagraphs, dataStream: insertDataStream } = insertBody;+ const { paragraphs: insertParagraphs } = insertBody;const paragraphIndexList = [];let firstInsertParagraphNextIndex = -1;@@ -234,20 +233,6 @@ export function insertParagraphs(deleteReptIndex = paragraphIndexList.indexOf(insertIndex);}- if (insertDataStream === DataStreamTreeTokenType.PARAGRAPH && insertParagraphs.length === 1) {- const nextParagraph = paragraphs[firstInsertParagraphNextIndex];- const insertParagraph = insertParagraphs[0];-- const nextParagraphStyle = nextParagraph.paragraphStyle;- const nextBullet = nextParagraph.bullet;-- nextParagraph.paragraphStyle = insertParagraph.paragraphStyle;- nextParagraph.bullet = insertParagraph.bullet;-- insertParagraph.paragraphStyle = nextParagraphStyle;- insertParagraph.bullet = nextBullet;- }-if (deleteReptIndex !== -1) {paragraphs.splice(deleteReptIndex, 1);}diff --git a/packages/core/src/docs/data-model/text-x/apply-utils/insert-apply.ts b/packages/core/src/docs/data-model/text-x/apply-utils/insert-apply.tsindex a2bc6cbb22..2663495016 100644--- a/packages/core/src/docs/data-model/text-x/apply-utils/insert-apply.ts+++ b/packages/core/src/docs/data-model/text-x/apply-utils/insert-apply.ts@@ -15,7 +15,6 @@*/import { insertTextToContent } from '../../../../shared';-import type { IDocumentBody } from '../../../../types/interfaces';import {insertCustomBlocks,insertCustomDecorations,@@ -25,6 +24,7 @@ import {insertTables,insertTextRuns,} from './common';+import type { IDocumentBody } from '../../../../types/interfaces';export function updateAttributeByInsert(body: IDocumentBody,diff --git a/packages/docs-ui/src/basics/custom-decoration-factory.ts b/packages/docs-ui/src/basics/custom-decoration-factory.tsindex b20f79c234..92cf7ba7d5 100644--- a/packages/docs-ui/src/basics/custom-decoration-factory.ts+++ b/packages/docs-ui/src/basics/custom-decoration-factory.ts@@ -88,17 +88,17 @@ export function addCustomDecorationBySelectionFactory(accessor: IAccessor, paramconst docSelectionManagerService = accessor.get(DocSelectionManagerService);const univerInstanceService = accessor.get(IUniverInstanceService);- const selections = docSelectionManagerService.getTextRanges();- if (!selections) {+ const documentDataModel = univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);+ if (!documentDataModel) {return false;}- const documentDataModel = univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);- if (!documentDataModel) {+ const unitId = documentDataModel.getUnitId();+ const selections = docSelectionManagerService.getTextRanges({ unitId, subUnitId: unitId });+ if (!selections) {return false;}const body = documentDataModel.getBody();- const unitId = documentDataModel.getUnitId();if (!body) {return false;}diff --git a/packages/docs-ui/src/basics/custom-range-factory.ts b/packages/docs-ui/src/basics/custom-range-factory.tsindex ecf8e30d70..59c39f7a14 100644--- a/packages/docs-ui/src/basics/custom-range-factory.ts+++ b/packages/docs-ui/src/basics/custom-range-factory.ts@@ -64,8 +64,7 @@ export function addCustomRangeBySelectionFactory(accessor: IAccessor, param: IAdconst { rangeId, rangeType, wholeEntity, properties, unitId, selection: propSelection } = param;const docSelectionManagerService = accessor.get(DocSelectionManagerService);const univerInstanceService = accessor.get(IUniverInstanceService);-- const selection = propSelection ?? docSelectionManagerService.getActiveTextRange();+ const selection = propSelection ?? docSelectionManagerService.getTextRanges({ unitId, subUnitId: unitId })?.[0];const segmentId = selection?.segmentId;if (!selection) {return false;diff --git a/packages/docs-ui/src/commands/commands/list.command.ts b/packages/docs-ui/src/commands/commands/list.command.tsindex 15dd38e2ae..69202f1dbd 100644--- a/packages/docs-ui/src/commands/commands/list.command.ts+++ b/packages/docs-ui/src/commands/commands/list.command.ts@@ -146,8 +146,8 @@ export const ListOperationCommand: ICommand<IListOperationCommandParams> = {? {paragraphStyle: {...paragraphStyle,- hanging: undefined,- indentStart: indentStart ? { v: Math.max(0, getNumberUnitValue(indentStart, charSpaceApply) + getNumberUnitValue(listHanging, charSpaceApply) - getNumberUnitValue(listIndentStart, charSpaceApply)) } : undefined,+ // hanging: undefined,+ // indentStart: indentStart ? { v: Math.max(0, getNumberUnitValue(indentStart, charSpaceApply) + getNumberUnitValue(listHanging, charSpaceApply) - getNumberUnitValue(listIndentStart, charSpaceApply)) } : undefined,},startIndex: 0,}@@ -155,9 +155,9 @@ export const ListOperationCommand: ICommand<IListOperationCommandParams> = {startIndex: 0,paragraphStyle: {...paragraphStyle,- indentFirstLine: undefined,- hanging: listHanging,- indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) },+ // indentFirstLine: undefined,+ // hanging: listHanging,+ // indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) },},bullet: {nestingLevel: bullet?.nestingLevel ?? 0,@@ -238,24 +238,24 @@ export const ChangeListTypeCommand: ICommand<IChangeListTypeCommandParams> = {const textX = new TextX();const jsonX = JSONX.getInstance();- const customLists = docDataModel.getSnapshot().lists ?? {};+ // const customLists = docDataModel.getSnapshot().lists ?? {};- const lists = {- ...PRESET_LIST_TYPE,- ...customLists,- };+ // const lists = {+ // ...PRESET_LIST_TYPE,+ // ...customLists,+ // };- const { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;+ // const { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;for (const paragraph of currentParagraphs) {const { startIndex, paragraphStyle = {}, bullet } = paragraph;- const { indentFirstLine, snapToGrid, indentStart } = paragraphStyle;- const paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {};+ // const { indentFirstLine, snapToGrid, indentStart } = paragraphStyle;+ // const paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {};// const bulletParagraphTextStyle = paragraphProperties.textStyle;- const { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties;- const { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES };+ // const { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties;+ // const { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES };- const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);+ // const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);textX.push({t: TextXActionType.RETAIN,@@ -273,9 +273,9 @@ export const ChangeListTypeCommand: ICommand<IChangeListTypeCommandParams> = {startIndex: 0,paragraphStyle: {...paragraphStyle,- indentFirstLine: undefined,- hanging: listHanging,- indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) },+ // indentFirstLine: undefined,+ // hanging: listHanging,+ // indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) },},bullet: {nestingLevel: bullet?.nestingLevel ?? 0,@@ -480,6 +480,7 @@ export const CheckListCommand: ICommand<IBulletListCommandParams> = {export interface IToggleCheckListCommandParams {index: number;segmentId?: string;+ textRanges?: ITextRangeWithStyle[];}export const ToggleCheckListCommand: ICommand<IToggleCheckListCommandParams> = {@@ -493,7 +494,7 @@ export const ToggleCheckListCommand: ICommand<IToggleCheckListCommandParams> = {}const univerInstanceService = accessor.get(IUniverInstanceService);const commandService = accessor.get(ICommandService);- const { index, segmentId } = params;+ const { index, segmentId, textRanges } = params;const docDataModel = univerInstanceService.getCurrentUniverDocInstance();if (docDataModel == null) {@@ -515,7 +516,7 @@ export const ToggleCheckListCommand: ICommand<IToggleCheckListCommandParams> = {params: {unitId,actions: [],- textRanges: [],+ textRanges: textRanges ?? [],segmentId,},};diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-checklist.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-checklist.render-controller.tsindex 24103e27e0..e1a6e9e67c 100644--- a/packages/docs-ui/src/controllers/render-controllers/doc-checklist.render-controller.ts+++ b/packages/docs-ui/src/controllers/render-controllers/doc-checklist.render-controller.ts@@ -38,9 +38,11 @@ export class DocChecklistRenderController extends Disposable implements IRenderMprivate _initPointerDownObserver() {this._docEventManagerService.clickBullets$.subscribe((paragraph) => {+ const textRanges = this._textSelectionManagerService.getTextRanges();this._commandService.executeCommand(ToggleCheckListCommand.id, {index: paragraph.paragraph.startIndex,segmentId: paragraph.segmentId,+ textRanges,});});}diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.tsindex 346fe54a5a..86fe176baa 100644--- a/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts+++ b/packages/docs-ui/src/controllers/render-controllers/doc-editor-bridge.controller.ts@@ -176,7 +176,7 @@ export class DocEditorBridgeController extends Disposable implements IRenderModuprivate _initialBlur() {this.disposeWithMe(this._editorService.blur$.subscribe(() => {- this._docSelectionRenderService.removeAllRanges();+ // this._docSelectionRenderService.removeAllRanges();this._docSelectionRenderService.blur();})diff --git a/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.tsindex 1c0f236a4c..d099bee259 100644--- a/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts+++ b/packages/docs-ui/src/controllers/render-controllers/doc.render-controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import { FOCUSING_DOC, ICommandService, IContextService, Inject, RxDisposable } from '@univerjs/core';+import { ICommandService, IContextService, Inject, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';import { DocBackground, Documents, IRenderManagerService, Layer, PageLayoutType, ScrollBar, Viewport } from '@univerjs/engine-render';import { takeUntil } from 'rxjs';@@ -33,7 +33,8 @@ export class DocRenderController extends RxDisposable implements IRenderModule {@Inject(DocSelectionRenderService) private readonly _docSelectionRenderService: DocSelectionRenderService,@Inject(DocSkeletonManagerService) private readonly _docSkeletonManagerService: DocSkeletonManagerService,@IEditorService private readonly _editorService: IEditorService,- @IRenderManagerService private readonly _renderManagerService: IRenderManagerService+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService) {super();@@ -82,7 +83,8 @@ export class DocRenderController extends RxDisposable implements IRenderModule {scene.attachControl();scene.onMouseWheel$.subscribeEvent((evt: unknown, state: EventState) => {- if (!this._contextService.getContextValue(FOCUSING_DOC)) {+ const currentDocUnit = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);+ if (currentDocUnit?.getUnitId() !== this._context.unitId) {return;}diff --git a/packages/engine-render/src/components/docs/extensions/font-and-base-line.ts b/packages/engine-render/src/components/docs/extensions/font-and-base-line.tsindex adcd0ffec6..1dd607c111 100644--- a/packages/engine-render/src/components/docs/extensions/font-and-base-line.ts+++ b/packages/engine-render/src/components/docs/extensions/font-and-base-line.ts@@ -113,7 +113,6 @@ export class FontAndBaseLine extends docExtension {const size = Math.ceil((glyph.ts?.fs ?? 12) * 1.2);// const MAGIC_OFFSET = 3;// const lineHeight = glyph.parent?.parent?.lineHeight ?? 0;- // console.log('===lineHeight', lineHeight, spanPointWithFont);ctx.translate(spanPointWithFont.x, spanPointWithFont.y - size);Checkbox.drawWith(ctx, {width: size,diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsxindex 6574bee395..9ad9f5af27 100644--- a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx+++ b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx@@ -14,11 +14,12 @@* limitations under the License.*/-import { BuildTextUtils, createInternalEditorID, CustomRangeType, DOCS_ZEN_EDITOR_UNIT_ID_KEY, FOCUSING_SHEET, generateRandomId, getOriginCellValue, ICommandService, IContextService, isValidRange, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, useDependency } from '@univerjs/core';+import { BuildTextUtils, createInternalEditorID, CustomRangeType, DisposableCollection, DOCS_ZEN_EDITOR_UNIT_ID_KEY, FOCUSING_SHEET, generateRandomId, getOriginCellValue, ICommandService, IContextService, isValidRange, IUniverInstanceService, LocaleService, Tools, UniverInstanceType, useDependency } from '@univerjs/core';import { Button, FormLayout, Input, Select } from '@univerjs/design';import { DocSelectionManagerService } from '@univerjs/docs';-import { RangeSelector } from '@univerjs/docs-ui';+import { DocSelectionRenderService, RangeSelector } from '@univerjs/docs-ui';import { deserializeRangeWithSheet, IDefinedNamesService, serializeRange, serializeRangeToRefString, serializeRangeWithSheet } from '@univerjs/engine-formula';+import { IRenderManagerService } from '@univerjs/engine-render';import { SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets';import { SheetHyperLinkType } from '@univerjs/sheets-hyper-link';import { IEditorBridgeService, IMarkSelectionService, ScrollToRangeOperation } from '@univerjs/sheets-ui';@@ -54,6 +55,7 @@ export const CellLinkEdit = () => {const sidePanelService = useDependency(SheetsHyperLinkSidePanelService);const sidePanelOptions = useMemo(() => sidePanelService.getOptions(), [sidePanelService]);const zenZoneService = useDependency(IZenZoneService);+ const renderManagerService = useDependency(IRenderManagerService);const markSelectionService = useDependency(IMarkSelectionService);const textSelectionService = useDependency(DocSelectionManagerService);const contextService = useDependency(IContextService);@@ -200,10 +202,22 @@ export const CellLinkEdit = () => {const payloadInitial = useMemo(() => payload, [type]);useEffect(() => {+ const render = renderManagerService.getRenderById(editorBridgeService.getCurrentEditorId());+ const disposeCollection = new DisposableCollection();++ if (render) {+ const selectionRenderService = render.with(DocSelectionRenderService);+ selectionRenderService.setReserveRangesStatus(true);+ disposeCollection.add(() => {+ selectionRenderService.setReserveRangesStatus(false);+ });+ }+return () => {editorBridgeService.disableForceKeepVisible();+ disposeCollection.dispose();};- }, [editorBridgeService]);+ }, [editorBridgeService, renderManagerService]);const linkTypeOptions: Array<{label: string;diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.tsindex 3374fa5698..3fbdd70e8d 100644--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts@@ -28,7 +28,6 @@ import {ICommandService,IContextService,Inject,- IResourceLoaderService,isFormulaString,IUndoRedoService,IUniverInstanceService,@@ -122,8 +121,7 @@ export class EditingRenderController extends Disposable implements IRenderModule@Inject(DocSelectionManagerService) private readonly _textSelectionManagerService: DocSelectionManagerService,@ICommandService private readonly _commandService: ICommandService,@Inject(LocaleService) protected readonly _localService: LocaleService,- @IEditorService private readonly _editorService: IEditorService,- @IResourceLoaderService private readonly _resourceLoaderService: IResourceLoaderService+ @IEditorService private readonly _editorService: IEditorService) {super();@@ -833,7 +831,7 @@ export class EditingRenderController extends Disposable implements IRenderModule}private async _handleEditorInvisible(param: IEditorBridgeServiceVisibleParam) {- const { keycode } = param;+ let { keycode } = param;this._setOpenForCurrent(null, null);this._cursorChange = CursorChange.InitialState;@@ -846,13 +844,11 @@ export class EditingRenderController extends Disposable implements IRenderModule}const { unitId, sheetId, row, column, documentLayoutObject } = editCellState;-// If neither the formula bar editor nor the cell editor has been edited,// it is considered that the content has not changed and returns directly.const editorIsDirty = this._editorBridgeService.getEditorDirty();if (editorIsDirty === false) {- this._moveCursor(keycode);- return;+ keycode = KeyCode.ESC;}const workbook = this._context.unit;diff --git a/packages/sheets-ui/src/controllers/render-controllers/editor-bridge.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/editor-bridge.render-controller.tsindex db7454cea1..1508acd8c6 100644--- a/packages/sheets-ui/src/controllers/render-controllers/editor-bridge.render-controller.ts+++ b/packages/sheets-ui/src/controllers/render-controllers/editor-bridge.render-controller.ts@@ -209,10 +209,14 @@ export class EditorBridgeRenderController extends RxDisposable implements IRendeif (options?.fromCollab) return;+ if (COMMAND_LISTENER_SKELETON_CHANGE.includes(command.id)) {+ this._hideEditor();+ }+ }));++ d.add(this._commandService.beforeCommandExecuted((command: ICommandInfo, options?: IExecutionOptions) => {if (command.id === SetWorksheetActiveOperation.id) {this._tryHideEditor();- } else if (COMMAND_LISTENER_SKELETON_CHANGE.includes(command.id)) {- this._hideEditor();}}));}