Skip to content

Commit

Permalink
fix(doc-mention): doc mention error (#4077)
Browse files Browse the repository at this point in the history
  • Loading branch information
weird94 authored Nov 15, 2024
1 parent 403381b commit d3085e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -50,7 +52,8 @@ export const AddDocMentionCommand: ICommand<IAddDocMentionCommandParams> = {
rangeType: CustomRangeType.MENTION,
wholeEntity: true,
properties: {
mention,
...mentionConfig,
...extra,
},
}],
};
Expand All @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions packages/docs-ui/src/commands/commands/core-editing.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -179,7 +187,7 @@ export const DeleteCommand: ICommand<IDeleteCommandParams> = {

textX.push({
t: TextXActionType.DELETE,
len,
len: end - start + 1,
});

const path = getRichTextEditPath(docDataModel, segmentId);
Expand Down
4 changes: 1 addition & 3 deletions packages/docs/src/utils/replace-selection-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

0 comments on commit d3085e2

Please sign in to comment.