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: inline style undo error at the doc end (#2241)

Ran Luo91e6fbceebbc
diff --git a/examples/src/data/docs/default-document-data-cn.ts b/examples/src/data/docs/default-document-data-cn.ts
index 468ca85c57..91fa570ce0 100644
--- a/examples/src/data/docs/default-document-data-cn.ts
+++ b/examples/src/data/docs/default-document-data-cn.ts
@@ -187,7 +187,7 @@ export const DEFAULT_DOCUMENT_DATA_CN: IDocumentData = {
},
{
st: 14,
- ed: 3057,
+ ed: 3064,
ts: {
fs: 12,
ff: 'Microsoft YaHei',
@@ -703,12 +703,12 @@ export const DEFAULT_DOCUMENT_DATA_CN: IDocumentData = {
sectionBreaks: [
{
startIndex: 3066,
- columnProperties: [
- {
- width: ptToPixel(240),
- paddingEnd: ptToPixel(15),
- },
- ],
+ // columnProperties: [
+ // {
+ // width: ptToPixel(240),
+ // paddingEnd: ptToPixel(15),
+ // },
+ // ],
columnSeparatorType: ColumnSeparatorType.NONE,
sectionType: SectionType.SECTION_TYPE_UNSPECIFIED,
// textDirection: textDirectionDocument,
diff --git a/examples/src/docs/main.ts b/examples/src/docs/main.ts
index bd530e1fc5..ae6f241809 100644
--- a/examples/src/docs/main.ts
+++ b/examples/src/docs/main.ts
@@ -25,7 +25,7 @@ import { UniverImagePlugin } from '@univerjs/image';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
-import { DEFAULT_DOCUMENT_DATA_EN } from '../data';
+import { DEFAULT_DOCUMENT_DATA_CN } from '../data';
import { DebuggerPlugin } from '../plugins/debugger';
@@ -67,7 +67,7 @@ univer.registerPlugin(UniverDocsUIPlugin, {
univer.registerPlugin(UniverImagePlugin);
-univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_EN);
+univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_CN);
// use for console test
declare global {
diff --git a/packages/core/src/docs/data-model/__tests__/apply-utils.spec.ts b/packages/core/src/docs/data-model/__tests__/apply-utils.spec.ts
index 0929d2d527..c22b2b3502 100644
--- a/packages/core/src/docs/data-model/__tests__/apply-utils.spec.ts
+++ b/packages/core/src/docs/data-model/__tests__/apply-utils.spec.ts
@@ -91,7 +91,7 @@ describe('test case in apply utils', () => {
it('the inserted textRun is between two testRuns', async () => {
const removedTextRuns = deleteTextRuns(body as IDocumentBody, 10, 20);
- expect(removedTextRuns.length).toBe(0);
+ expect(removedTextRuns.length).toBe(1);
expect(body?.textRuns![2].st).toBe(20);
expect(body?.textRuns![2].ed).toBe(30);
});
diff --git a/packages/core/src/docs/data-model/apply-utils/common.ts b/packages/core/src/docs/data-model/apply-utils/common.ts
index c8f40e14b8..085bb89f54 100644
--- a/packages/core/src/docs/data-model/apply-utils/common.ts
+++ b/packages/core/src/docs/data-model/apply-utils/common.ts
@@ -378,6 +378,7 @@ export function insertCustomRanges(
}
}
+// eslint-disable-next-line max-lines-per-function
export function deleteTextRuns(body: IDocumentBody, textLength: number, currentIndex: number) {
const { textRuns } = body;
const startIndex = currentIndex;
@@ -454,6 +455,16 @@ export function deleteTextRuns(body: IDocumentBody, textLength: number, currentI
body.textRuns = newTextRuns;
}
+ // In the case of no style before, add the style, removeTextRuns will be empty,
+ // in this case, you need to add an empty textRun for undo.
+ if (removeTextRuns.length === 0) {
+ removeTextRuns.push({
+ st: 0,
+ ed: textLength,
+ ts: {},
+ });
+ }
+
return removeTextRuns;
}
diff --git a/packages/core/src/docs/data-model/apply-utils/update-apply.ts b/packages/core/src/docs/data-model/apply-utils/update-apply.ts
index 52cf9e4cd4..2b3b35f98c 100644
--- a/packages/core/src/docs/data-model/apply-utils/update-apply.ts
+++ b/packages/core/src/docs/data-model/apply-utils/update-apply.ts
@@ -97,6 +97,7 @@ function updateTextRuns(
return removeTextRuns;
}
+// eslint-disable-next-line max-lines-per-function
export function coverTextRuns(
updateDataTextRuns: ITextRun[],
removeTextRuns: ITextRun[],