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.

refactor: always insert a paragraph before table (#3925)

Ran Luo1dfbd104a66e
diff --git a/packages/core/src/docs/data-model/text-x/text-x.ts b/packages/core/src/docs/data-model/text-x/text-x.ts
index 64c7828ffe..7908239d7f 100644
--- a/packages/core/src/docs/data-model/text-x/text-x.ts
+++ b/packages/core/src/docs/data-model/text-x/text-x.ts
@@ -130,6 +130,7 @@ export class TextX {
return this._transform(otherActions, thisActions, priority === 'left' ? 'right' : 'left');
}
+ // otherActions is the actions to be transformed.
static _transform(thisActions: TextXAction[], otherActions: TextXAction[], priority: TPriority = 'right'): TextXAction[] {
const thisIter = new ActionIterator(thisActions);
diff --git a/packages/docs-ui/src/commands/commands/table/doc-table-create.command.ts b/packages/docs-ui/src/commands/commands/table/doc-table-create.command.ts
index 68ba027f0e..654b5d5eb6 100644
--- a/packages/docs-ui/src/commands/commands/table/doc-table-create.command.ts
+++ b/packages/docs-ui/src/commands/commands/table/doc-table-create.command.ts
@@ -36,7 +36,7 @@ export const CreateDocTableCommand: ICommand<ICreateDocTableCommandParams> = {
id: CreateDocTableCommandId,
type: CommandType.COMMAND,
- // eslint-disable-next-line max-lines-per-function, complexity
+ // eslint-disable-next-line max-lines-per-function
handler: async (accessor, params: ICreateDocTableCommandParams) => {
const { rowCount, colCount } = params;
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
@@ -66,16 +66,17 @@ export const CreateDocTableCommand: ICommand<ICreateDocTableCommandParams> = {
const paragraphs = body.paragraphs ?? [];
const prevParagraph = paragraphs.find((p) => p.startIndex >= startOffset);
const curGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage);
- const line = curGlyph?.parent?.parent;
- const preGlyph = skeleton.findNodeByCharIndex(startOffset - 1, segmentId, segmentPage);
- const isInParagraph = preGlyph && preGlyph.content !== '\r';
+ // const line = curGlyph?.parent?.parent;
+ // const preGlyph = skeleton.findNodeByCharIndex(startOffset - 1, segmentId, segmentPage);
+ // const isInParagraph = preGlyph && preGlyph.content !== '\r';
- if (curGlyph == null || line == null) {
+ if (curGlyph == null) {
return false;
}
// Also need to create new paragraph when there is already a table in paragraph.
- const needCreateParagraph = isInParagraph || line.isBehindTable;
+ // Always inert a paragraph before table.
+ const needCreateParagraph = true; // isInParagraph || line.isBehindTable;
const textX = new TextX();
const jsonX = JSONX.getInstance();