Skip to content

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.

fix(docs-thread-comment-ui): comment when cross table (#2939)

zhangw678816cff448
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.ts
index cb3d104611..2633a2b438 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
@@ -619,7 +619,6 @@ export function deleteParagraphs(body: IDocumentBody, textLength: number, curren
const { paragraphs } = body;
const startIndex = currentIndex;
-
const endIndex = currentIndex + textLength;
const removeParagraphs: IParagraph[] = [];
let removeAfterFirstNew: Nullable<IParagraph> = null;
@@ -630,7 +629,6 @@ export function deleteParagraphs(body: IDocumentBody, textLength: number, curren
for (let i = 0, len = paragraphs.length; i < len; i++) {
const paragraph = paragraphs[i];
const { startIndex: index } = paragraph;
-
if (index >= startIndex && index < endIndex) {
removeParagraphs.push({
...paragraph,
@@ -638,7 +636,6 @@ export function deleteParagraphs(body: IDocumentBody, textLength: number, curren
});
isRemove = true;
-
continue;
} else if (index >= endIndex) {
paragraph.startIndex -= textLength;
diff --git a/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts b/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts
index 9f0431377e..068cf35638 100644
--- a/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts
+++ b/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts
@@ -16,14 +16,14 @@
import type { DocumentDataModel, IAccessor, ICommand } from '@univerjs/core';
import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
+import { DocSkeletonManagerService, serializeDocRange, TextSelectionManagerService } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';
import { DocHyperLinkPopupService } from '../../services/hyper-link-popup.service';
export const shouldDisableAddLink = (accessor: IAccessor) => {
const textSelectionService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
- const activeRange = textSelectionService.getActiveTextRangeWithStyle();
+ const textRanges = textSelectionService.getCurrentTextRanges()?.map(serializeDocRange);
const renderManagerService = accessor.get(IRenderManagerService);
const render = renderManagerService.getCurrent();
const skeleton = render?.with(DocSkeletonManagerService).getSkeleton();
@@ -31,30 +31,33 @@ export const shouldDisableAddLink = (accessor: IAccessor) => {
if (editArea === DocumentEditArea.FOOTER || editArea === DocumentEditArea.HEADER) {
return true;
}
+ if (!textRanges || textRanges.length > 1) {
+ return true;
+ }
+
+ const activeRange = textRanges[0];
const doc = univerInstanceService.getCurrentUnitForType<DocumentDataModel>(UniverInstanceType.UNIVER_DOC);
if (!doc || !activeRange || activeRange.collapsed) {
- return (true);
+ return true;
}
const paragraphs = doc.getBody()?.paragraphs;
if (!paragraphs) {
- return (true);
- return;
+ return true;
}
for (let i = 0, len = paragraphs.length; i < len; i++) {
const p = paragraphs[i];
- if ((activeRange.startOffset) <= p.startIndex && activeRange.endOffset > p.startIndex) {
- return (true);
- return;
+ if (activeRange.startOffset <= p.startIndex && activeRange.endOffset > p.startIndex) {
+ return true;
}
- if (p.startIndex > activeRange.endOffset) {
+ if (p.startIndex > activeRange.endOffset!) {
break;
}
}
- return (false);
+ return false;
};
export interface IShowDocHyperLinkEditPopupOperationParams {
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.ts
index c241d331cf..e3cdc20af2 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
@@ -15,7 +15,7 @@
*/
import type { Documents, IRenderContext, IRenderModule, Viewport } from '@univerjs/engine-render';
-import { CURSOR_TYPE, getParagraphByGlyph, PageLayoutType, Vector2 } from '@univerjs/engine-render';
+import { CURSOR_TYPE, getParagraphByGlyph, GlyphType, PageLayoutType, Vector2 } from '@univerjs/engine-render';
import type { DocumentDataModel } from '@univerjs/core';
import { Disposable, ICommandService, Inject, PresetListType } from '@univerjs/core';
import { DocSkeletonManagerService, ToggleCheckListCommand, VIEWPORT_KEY } from '@univerjs/docs';
@@ -60,10 +60,8 @@ export class DocChecklistRenderController extends Disposable implements IRenderM
if (!node) {
return;
}
- const index = node.node.parent!.st! + node.node.parent!.glyphGroup.indexOf(node.node)!;
-
const paragraph = getParagraphByGlyph(node.node, this._context.unit.getBody());
- if (paragraph && paragraph.bullet && index === paragraph.paragraphStart) {
+ if (paragraph && paragraph.bullet && node.node.glyphType === GlyphType.LIST) {
if (
paragraph.bullet.listType === PresetListType.CHECK_LIST ||
paragraph.bullet.listType === PresetListType.CHECK_LIST_CHECKED
diff --git a/packages/docs/src/basics/custom-decoration-factory.ts b/packages/docs/src/basics/custom-decoration-factory.ts
index 6d0c1bd76b..79c13c0220 100644
--- a/packages/docs/src/basics/custom-decoration-factory.ts
+++ b/packages/docs/src/basics/custom-decoration-factory.ts
@@ -18,20 +18,19 @@ import type { CustomDecorationType, DocumentDataModel, IAccessor, IMutationInfo,
import { getBodySlice, IUniverInstanceService, JSONX, TextX, TextXActionType, Tools, UniverInstanceType, UpdateDocsAttributeType } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '../commands/mutations/core-editing.mutation';
import { RichTextEditingMutation } from '../commands/mutations/core-editing.mutation';
-import { TextSelectionManagerService } from '../services/text-selection-manager.service';
+import { serializeDocRange, TextSelectionManagerService } from '../services/text-selection-manager.service';
interface IAddCustomDecorationParam {
unitId: string;
- range: ITextRange;
+ ranges: ITextRange[];
segmentId?: string;
id: string;
type: CustomDecorationType;
}
export function addCustomDecorationFactory(param: IAddCustomDecorationParam) {
- const { unitId, range, id, type, segmentId } = param;
+ const { unitId, ranges, id, type, segmentId } = param;
- const { startOffset: start, endOffset: end } = range;
const doMutation: IMutationInfo<IRichTextEditingMutationParams> = {
id: RichTextEditingMutation.id,
params: {
@@ -43,29 +42,36 @@ export function addCustomDecorationFactory(param: IAddCustomDecorationParam) {
const textX = new TextX();
const jsonX = JSONX.getInstance();
+ let cursor = 0;
+
+ for (let i = 0; i < ranges.length; i++) {
+ const range = ranges[i];
+ const { startOffset: start, endOffset: end } = range;
+ if (start > 0) {
+ textX.push({
+ t: TextXActionType.RETAIN,
+ len: start - cursor,
+ segmentId,
+ });
+ }
- if (start > 0) {
textX.push({
t: TextXActionType.RETAIN,
- len: start,
+ body: {
+ dataStream: '',
+ customDecorations: [{
+ id,
+ type,
+ startIndex: 0,
+ endIndex: end - start - 1,
+ }],
+ },
+ len: end - start,
segmentId,
});
- }
- textX.push({
- t: TextXActionType.RETAIN,
- body: {
- dataStream: '',
- customDecorations: [{
- id,
- type,
- startIndex: 0,
- endIndex: end - start - 1,
- }],
- },
- len: end - start,
- segmentId,
- });
+ cursor = end;
+ }
doMutation.params.actions = jsonX.editOp(textX.serialize());
return doMutation;
@@ -82,8 +88,8 @@ export function addCustomDecorationBySelectionFactory(accessor: IAccessor, param
const textSelectionManagerService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
- const selection = textSelectionManagerService.getActiveTextRangeWithStyle();
- if (!selection) {
+ const selections = textSelectionManagerService.getCurrentTextRanges();
+ if (!selections) {
return false;
}
@@ -100,11 +106,7 @@ export function addCustomDecorationBySelectionFactory(accessor: IAccessor, param
const doMutation = addCustomDecorationFactory(
{
unitId,
- range: {
- startOffset: selection.startOffset,
- endOffset: selection.endOffset,
- collapsed: true,
- },
+ ranges: selections.map(serializeDocRange),
id,
type,
segmentId,
diff --git a/packages/docs/src/commands/commands/auto-format.command.ts b/packages/docs/src/commands/commands/auto-format.command.ts
index 50868cffab..8753ab9fa8 100644
--- a/packages/docs/src/commands/commands/auto-format.command.ts
+++ b/packages/docs/src/commands/commands/auto-format.command.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { CommandType, type ICommand, ICommandService, sequenceExecute } from '@univerjs/core';
+import { CommandType, type ICommand, ICommandService, sequenceExecuteAsync } from '@univerjs/core';
import { DocAutoFormatService } from '../../services/doc-auto-format.service';
const TabCommandId = 'doc.command.tab';
@@ -26,10 +26,10 @@ export interface ITabCommandParams {
export const TabCommand: ICommand<ITabCommandParams> = {
id: TabCommandId,
type: CommandType.COMMAND,
- handler(accessor, params) {
+ async handler(accessor, params) {
const autoFormatService = accessor.get(DocAutoFormatService);
const mutations = autoFormatService.onAutoFormat(TabCommand.id, params);
- return sequenceExecute(mutations, accessor.get(ICommandService)).result;
+ return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
},
};
@@ -38,19 +38,19 @@ const AfterSpaceCommandId = 'doc.command.after-space';
export const AfterSpaceCommand: ICommand = {
id: AfterSpaceCommandId,
type: CommandType.COMMAND,
- handler(accessor) {
+ async handler(accessor) {
const autoFormatService = accessor.get(DocAutoFormatService);
const mutations = autoFormatService.onAutoFormat(AfterSpaceCommand.id);
- return sequenceExecute(mutations, accessor.get(ICommandService)).result;
+ return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
},
};
export const EnterCommand: ICommand = {
id: 'doc.command.enter',
type: CommandType.COMMAND,
- handler(accessor) {
+ async handler(accessor) {
const autoFormatService = accessor.get(DocAutoFormatService);
const mutations = autoFormatService.onAutoFormat(EnterCommand.id);
- return sequenceExecute(mutations, accessor.get(ICommandService)).result;
+ return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
},
};
diff --git a/packages/docs/src/commands/commands/break-line.command.ts b/packages/docs/src/commands/commands/break-line.command.ts
index 6a3fae6e7f..db623921fa 100644
--- a/packages/docs/src/commands/commands/break-line.command.ts
+++ b/packages/docs/src/commands/commands/break-line.command.ts
@@ -102,13 +102,13 @@ export const BreakLineCommand: ICommand = {
const prevParagraph = paragraphs.find((p) => p.startIndex >= startOffset);
// line breaks to 2
if (prevParagraph && prevParagraph.startIndex > endOffset) {
- const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex));
+ const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex + 1));
bodyAfter.customRanges = bodyAfter.customRanges?.map((range) => customRangeService.copyCustomRange(unitId, range));
const deleteRange = {
startOffset,
- endOffset: prevParagraph.startIndex,
+ endOffset: prevParagraph.startIndex + 1,
collapsed: false,
};
updateAttributeByInsert(
@@ -120,6 +120,7 @@ export const BreakLineCommand: ICommand = {
1,
0
);
+
const result = await commandService.executeCommand(InsertCommand.id, {
unitId,
body: bodyAfter,
diff --git a/packages/docs/src/commands/commands/list.command.ts b/packages/docs/src/commands/commands/list.command.ts
index bb9fa98fec..78a292d7e9 100644
--- a/packages/docs/src/commands/commands/list.command.ts
+++ b/packages/docs/src/commands/commands/list.command.ts
@@ -510,7 +510,6 @@ export const ToggleCheckListCommand: ICommand<IToggleCheckListCommandParams> = {
if (!params) {
return false;
}
- const textSelectionManagerService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
const { index } = params;
@@ -520,11 +519,7 @@ export const ToggleCheckListCommand: ICommand<IToggleCheckListCommandParams> = {
return false;
}
- // const { segmentId } = activeRange;
-
- const selections = textSelectionManagerService.getCurrentTextRanges() ?? [];
const paragraphs = docDataModel.getBody()?.paragraphs;
- const serializedSelections = selections.map(serializeDocRange);
if (paragraphs == null) {
return false;
}
@@ -534,13 +529,12 @@ export const ToggleCheckListCommand: ICommand<IToggleCheckListCommandParams> = {
if (!currentParagraph?.bullet || currentParagraph.bullet.listType.indexOf(PresetListType.CHECK_LIST) === -1) {
return false;
}
-
const doMutation: IMutationInfo<IRichTextEditingMutationParams> = {
id: RichTextEditingMutation.id,
params: {
unitId,
actions: [],
- textRanges: serializedSelections,
+ textRanges: [],
},
};
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.ts
index 84b9480601..27d467e24d 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
@@ -17,7 +17,7 @@
import type { IScale } from '@univerjs/core';
import { BaselineOffset, getColorStyle } from '@univerjs/core';
-import { hasCJK } from '../../../basics';
+import { GlyphType, hasCJK } from '../../../basics';
import { COLOR_BLACK_RGB } from '../../../basics/const';
import type { IDocumentSkeletonGlyph } from '../../../basics/i-document-skeleton-cached';
import { Vector2 } from '../../../basics/vector2';
@@ -106,14 +106,17 @@ export class FontAndBaseLine extends docExtension {
ctx.fillText(content, 0, 0);
ctx.restore();
} else {
- if (content === '\u2610' || content === '\u2611') {
+ const CHECKED_GLYPH = '\u2611';
+ const UNCHECKED_GLYPH = '\u2610';
+ if ((content === UNCHECKED_GLYPH || content === CHECKED_GLYPH) && glyph.glyphType === GlyphType.LIST) {
ctx.save();
const size = glyph.ts?.fs ?? 16;
- ctx.translate(spanStartPoint.x, spanStartPoint.y + centerPoint.y - size);
+ const MAGIC_OFFSET = 3;
+ ctx.translate(spanPointWithFont.x, spanPointWithFont.y - (bBox.aba + bBox.abd) - MAGIC_OFFSET);
Checkbox.drawWith(ctx, {
width: size,
height: size,
- checked: content === '\u2611',
+ checked: content === CHECKED_GLYPH,
});
ctx.restore();
} else {
diff --git a/packages/engine-render/src/components/docs/layout/model/glyph.ts b/packages/engine-render/src/components/docs/layout/model/glyph.ts
index 499058a653..b716e44fe3 100644
--- a/packages/engine-render/src/components/docs/layout/model/glyph.ts
+++ b/packages/engine-render/src/components/docs/layout/model/glyph.ts
@@ -282,6 +282,9 @@ export function createSkeletonBulletGlyph(
ts: {
...glyph.ts,
...textStyle,
+ st: {
+ s: BooleanNumber.FALSE,
+ },
},
fontStyle,
width,