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(doc-mention): doc mention error (#4077)
zhangwd3085e284850
diff --git a/packages/docs-mention-ui/src/commands/commands/doc-mention.command.ts b/packages/docs-mention-ui/src/commands/commands/doc-mention.command.tsindex b197c86ff8..1e7c8dae9e 100644--- a/packages/docs-mention-ui/src/commands/commands/doc-mention.command.ts+++ b/packages/docs-mention-ui/src/commands/commands/doc-mention.command.ts@@ -40,6 +40,8 @@ export const AddDocMentionCommand: ICommand<IAddDocMentionCommandParams> = {if (!activeRange) {return false;}++ const { extra, ...mentionConfig } = mention;const dataStream = ` @${mention.label} `;const body: IDocumentBody = {dataStream,@@ -50,7 +52,8 @@ export const AddDocMentionCommand: ICommand<IAddDocMentionCommandParams> = {rangeType: CustomRangeType.MENTION,wholeEntity: true,properties: {- mention,+ ...mentionConfig,+ ...extra,},}],};@@ -69,7 +72,7 @@ export const AddDocMentionCommand: ICommand<IAddDocMentionCommandParams> = {);if (doMutation) {- return commandService.executeCommand(doMutation.id, doMutation.params);+ return commandService.syncExecuteCommand(doMutation.id, doMutation.params);}return false;diff --git a/packages/docs-ui/src/commands/commands/core-editing.command.ts b/packages/docs-ui/src/commands/commands/core-editing.command.tsindex eef7ed2d03..f350c84859 100644--- a/packages/docs-ui/src/commands/commands/core-editing.command.ts+++ b/packages/docs-ui/src/commands/commands/core-editing.command.ts@@ -152,7 +152,15 @@ export const DeleteCommand: ICommand<IDeleteCommandParams> = {}const { startOffset } = range;- const start = direction === DeleteDirection.LEFT ? startOffset - len : startOffset;+ let start = direction === DeleteDirection.LEFT ? startOffset - len : startOffset;+ let end = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset + len - 1;++ const customRange = body.customRanges?.find((customRange) => customRange.startIndex <= start && customRange.endIndex >= end);++ if (customRange?.wholeEntity) {+ start = customRange.startIndex;+ end = Math.max(end, customRange.endIndex);+ }const doMutation: IMutationInfo<IRichTextEditingMutationParams> = {id: RichTextEditingMutation.id,@@ -179,7 +187,7 @@ export const DeleteCommand: ICommand<IDeleteCommandParams> = {textX.push({t: TextXActionType.DELETE,- len,+ len: end - start + 1,});const path = getRichTextEditPath(docDataModel, segmentId);diff --git a/packages/docs/src/utils/replace-selection-factory.ts b/packages/docs/src/utils/replace-selection-factory.tsindex 0bcc7d6067..7fbee96b80 100644--- a/packages/docs/src/utils/replace-selection-factory.ts+++ b/packages/docs/src/utils/replace-selection-factory.ts@@ -20,7 +20,6 @@ import type { IRichTextEditingMutationParams } from '../commands/mutations/core-import { BuildTextUtils, IUniverInstanceService, JSONX } from '@univerjs/core';import { RichTextEditingMutation } from '../commands/mutations/core-editing.mutation';import { DocSelectionManagerService } from '../services/doc-selection-manager.service';-import { getRichTextEditPath } from './custom-range-factory';export interface IReplaceSelectionFactoryParams {unitId: string;@@ -89,7 +88,6 @@ export function replaceSelectionFactory(accessor: IAccessor, params: IReplaceSel};const jsonX = JSONX.getInstance();- const path = getRichTextEditPath(docDataModel, segmentId);- doMutation.params.actions = jsonX.editOp(textX.serialize(), path);+ doMutation.params.actions = jsonX.editOp(textX.serialize());return doMutation;}