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): delete paragraph break in table cell (#3077)

Ran Luodc566fdff1ff
diff --git a/packages/docs/src/commands/commands/delete.command.ts b/packages/docs/src/commands/commands/delete.command.ts
index 3d157262d8..d753a4ca71 100644
--- a/packages/docs/src/commands/commands/delete.command.ts
+++ b/packages/docs/src/commands/commands/delete.command.ts
@@ -173,8 +173,8 @@ export const MergeTwoParagraphCommand: ICommand<IMergeTwoParagraphParams> = {
}
const startIndex = direction === DeleteDirection.LEFT ? startOffset : startOffset + 1;
- const endIndex = originBody.paragraphs
- ?.find((p) => p.startIndex >= startIndex)?.startIndex!;
+ const endIndex = originBody.paragraphs!
+ .find((p) => p.startIndex >= startIndex)!.startIndex!;
const body = getParagraphBody(accessor, unitId, originBody, startIndex, endIndex);
const cursor = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset;
@@ -510,7 +510,7 @@ export const DeleteRightCommand: ICommand = {
id: 'doc.command.delete-right',
type: CommandType.COMMAND,
- // eslint-disable-next-line max-lines-per-function
+ // eslint-disable-next-line max-lines-per-function, complexity
handler: async (accessor) => {
const textSelectionManagerService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -652,7 +652,13 @@ export const DeleteRightCommand: ICommand = {
},
};
-function getParagraphBody(accessor: IAccessor, unitId: string, body: IDocumentBody, start: number, end: number): IDocumentBody {
+function getParagraphBody(
+ accessor: IAccessor,
+ unitId: string,
+ body: IDocumentBody,
+ start: number,
+ end: number
+): IDocumentBody {
const { textRuns: originTextRuns = [], customBlocks: originCustomBlocks = [] } = body;
const dataStream = body.dataStream.substring(start, end);
const customRangeService = accessor.get(DocCustomRangeService);
diff --git a/packages/docs/src/commands/commands/table/table.ts b/packages/docs/src/commands/commands/table/table.ts
index 0e663f73ce..40cb49b762 100644
--- a/packages/docs/src/commands/commands/table/table.ts
+++ b/packages/docs/src/commands/commands/table/table.ts
@@ -221,7 +221,7 @@ export function getInsertRowBody(col: number) {
for (let i = 0; i < col; i++) {
dataStream += `${DataStreamTreeTokenType.TABLE_CELL_START}\r\n${DataStreamTreeTokenType.TABLE_CELL_END}`;
paragraphs.push({
- startIndex: dataStream.length - 2,
+ startIndex: dataStream.length - 3,
paragraphStyle: {
spaceAbove: { v: 3 },
lineSpacing: 2,
@@ -229,7 +229,7 @@ export function getInsertRowBody(col: number) {
},
});
sectionBreaks.push({
- startIndex: dataStream.length - 1,
+ startIndex: dataStream.length - 2,
});
}