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: fix the judgment logic of editor returning empty textRun (#3211)

ybzky9a57c5d56de2
diff --git a/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts b/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts
index fa86e86095..b9dd5e0e95 100644
--- a/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts
+++ b/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts
@@ -301,6 +301,30 @@ describe('Test EndEditController', () => {
// textRuns works on parts of strings
const isRichTextRes2 = isRichText(anotherCellBody);
expect(isRichTextRes2).toBe(true);
+
+ const cellBody2 = {
+ dataStream: 'true\r\n',
+ textRuns: [
+ {
+ ts: {},
+ st: 0,
+ ed: 0,
+ },
+ ],
+ paragraphs: [
+ {
+ startIndex: 4,
+ paragraphStyle: {
+ horizontalAlign: 0,
+ },
+ },
+ ],
+ customBlocks: [],
+ customRanges: [],
+ };
+
+ const isRichTextWithCellBody2 = isRichText(cellBody2);
+ expect(isRichTextWithCellBody2).toBe(false);
});
it('test number can not set style', () => {
diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
index ede5aea9f1..c9d73edade 100644
--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
@@ -1120,7 +1120,7 @@ export function isRichText(body: IDocumentBody): boolean {
const hasRichTextStyle = Boolean(textRun.ts && Object.keys(textRun.ts).some((property) => {
return richTextStyle.includes(property);
}));
- return hasRichTextStyle || (textRun.ts && (textRun.ed - textRun.st < bodyNoLineBreak.length));
+ return hasRichTextStyle || (Object.keys(textRun.ts ?? {}).length && (textRun.ed - textRun.st < bodyNoLineBreak.length));
}) ||
paragraphs.some((paragraph) => paragraph.bullet) ||
paragraphs.length >= 2 ||