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 format in cell with rich text (#1560)

Ran Luo447a095733f1
diff --git a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts
index abd8febe38..3138f04818 100644
--- a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts
+++ b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts
@@ -24,6 +24,7 @@ import type {
IMutation,
IMutationCommonParams,
IObjectMatrixPrimitiveType,
+ IParagraph,
IRange,
IStyleData,
ITextRun,
@@ -372,6 +373,14 @@ export function mergeStyle(
return backupStyle;
}
+function skipParagraphs(paragraphs: IParagraph[], offset: number): number {
+ if (paragraphs.some((p) => p.startIndex === offset)) {
+ return skipParagraphs(paragraphs, offset + 1);
+ }
+
+ return offset;
+}
+
/**
* Find the text style of all paragraphs and modify it to the new style
* @param p
@@ -388,11 +397,12 @@ export function mergeRichTextStyle(p: IDocumentData, newStyle: Nullable<IStyleDa
let index = 0;
const newTextRuns = [];
+ const paragraphs = p.body?.paragraphs || [];
for (const textRun of p.body.textRuns) {
const { st, ed, ts = {} } = textRun;
- if (index !== st) {
+ if (index < st) {
const tr: ITextRun = {
st: index,
ed: st,
@@ -408,27 +418,27 @@ export function mergeRichTextStyle(p: IDocumentData, newStyle: Nullable<IStyleDa
}
newTextRuns.push(tr);
- } else {
- const merge = mergeStyle(ts, newStyle, true);
+ }
- // then remove null
- merge && Tools.removeNull(merge);
+ const merge = mergeStyle(ts, newStyle, true);
- if (Tools.isEmptyObject(merge)) {
- delete textRun.ts;
- } else {
- textRun.ts = merge as ITextStyle;
- }
+ // then remove null
+ merge && Tools.removeNull(merge);
- newTextRuns.push(textRun);
+ if (Tools.isEmptyObject(merge)) {
+ delete textRun.ts;
+ } else {
+ textRun.ts = merge as ITextStyle;
}
- index = ed;
+ newTextRuns.push(textRun);
+
+ index = skipParagraphs(paragraphs, ed);
}
const endIndex = p.body.dataStream.endsWith('\r\n') ? p.body.dataStream.length - 2 : p.body.dataStream.length;
- if (index !== endIndex) {
+ if (index < endIndex) {
const tr: ITextRun = {
st: index,
ed: endIndex,
@@ -454,8 +464,8 @@ function isNumeric(str: string) {
}
function isSafeNumeric(str: string) {
- const numberic = isNumeric(str);
- if (!numberic) {
+ const numeric = isNumeric(str);
+ if (!numeric) {
return false;
}