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(sheets): save text editor style (#4570)

zhangw3059f037089d
diff --git a/packages/core/src/docs/data-model/rich-text-builder.ts b/packages/core/src/docs/data-model/rich-text-builder.ts
index 834e9469f8..915dba35c3 100644
--- a/packages/core/src/docs/data-model/rich-text-builder.ts
+++ b/packages/core/src/docs/data-model/rich-text-builder.ts
@@ -1730,10 +1730,10 @@ export class RichTextBuilder extends RichTextValue {
* @example
* ```ts
* const richText = RichTextValue.create({ body: { dataStream: 'Hello World\r\n' } });
- * const newRichText = richText.insertText(0, 'World');
+ * const newRichText = richText.insertText('World');
* ```
*/
- insertText(start: string, style?: TextStyleBuilder | ITextStyle): RichTextBuilder;
+ insertText(text: string, style?: TextStyleBuilder | ITextStyle): RichTextBuilder;
/**
* Inserts text into the rich text builder at the specified start position
* @param start The start position of the text to insert
@@ -2012,8 +2012,7 @@ export class RichTextBuilder extends RichTextValue {
}
/**
- * Inserts a new paragraph at the specified start position
- * @param {number} start The start position of the paragraph to insert
+ * Inserts a new paragraph to the end
* @param {ParagraphStyleBuilder} paragraphStyle The style of the paragraph to insert
* @returns {RichTextBuilder} The current RichTextBuilder instance
* @example
diff --git a/packages/docs-ui/src/basics/paragraph.ts b/packages/docs-ui/src/basics/paragraph.ts
index 9ce46f599d..dac5783c0e 100644
--- a/packages/docs-ui/src/basics/paragraph.ts
+++ b/packages/docs-ui/src/basics/paragraph.ts
@@ -24,12 +24,13 @@ export function getTextRunAtPosition(
textRuns: ITextRun[],
position: number,
defaultStyle: ITextStyle,
- cacheStyle: Nullable<ITextStyle>
+ cacheStyle: Nullable<ITextStyle>,
+ isCellEditor?: boolean
): ITextRun {
const retTextRun: ITextRun = {
st: 0,
ed: 0,
- ts: defaultStyle,
+ ts: isCellEditor ? {} : defaultStyle,
};
for (let i = textRuns.length - 1; i >= 0; i--) {
diff --git a/packages/docs-ui/src/commands/commands/ime-input.command.ts b/packages/docs-ui/src/commands/commands/ime-input.command.ts
index 54c9ec1506..a7a96c2f18 100644
--- a/packages/docs-ui/src/commands/commands/ime-input.command.ts
+++ b/packages/docs-ui/src/commands/commands/ime-input.command.ts
@@ -32,8 +32,6 @@ export interface IIMEInputCommandParams {
isCompositionEnd: boolean;
}
-const UNITS = SHEET_EDITOR_UNITS;
-
export const IMEInputCommand: ICommand<IIMEInputCommandParams> = {
id: 'doc.command.ime-input',
@@ -92,12 +90,13 @@ export const IMEInputCommand: ICommand<IIMEInputCommandParams> = {
const defaultTextStyle = docMenuStyleService.getDefaultStyle();
const styleCache = docMenuStyleService.getStyleCache();
- const curCustomRange = getCustomRangeAtPosition(body.customRanges ?? [], startOffset + oldTextLen, UNITS.includes(unitId));
+ const curCustomRange = getCustomRangeAtPosition(body.customRanges ?? [], startOffset + oldTextLen, SHEET_EDITOR_UNITS.includes(unitId));
const curTextRun = getTextRunAtPosition(
body.textRuns ?? [],
isCompositionStart ? endOffset : startOffset + oldTextLen,
defaultTextStyle,
- styleCache
+ styleCache,
+ SHEET_EDITOR_UNITS.includes(unitId)
);
const customDecorations = getCustomDecorationAtPosition(body.customDecorations ?? [], startOffset + oldTextLen);
diff --git a/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts b/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts
index fcd1c0ec65..e818e0231d 100644
--- a/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/doc-input.controller.ts
@@ -77,7 +77,7 @@ export class DocInputController extends Disposable implements IRenderModule {
const defaultTextStyle = this._docMenuStyleService.getDefaultStyle();
const cacheStyle = this._docMenuStyleService.getStyleCache();
const curCustomRange = getCustomRangeAtPosition(originBody?.customRanges ?? [], activeRange.endOffset, SHEET_EDITOR_UNITS.includes(unitId));
- const curTextRun = getTextRunAtPosition(originBody?.textRuns ?? [], activeRange.endOffset, defaultTextStyle, cacheStyle);
+ const curTextRun = getTextRunAtPosition(originBody?.textRuns ?? [], activeRange.endOffset, defaultTextStyle, cacheStyle, SHEET_EDITOR_UNITS.includes(unitId));
const curCustomDecorations = getCustomDecorationAtPosition(originBody?.customDecorations ?? [], activeRange.endOffset);
await this._commandService.executeCommand(InsertCommand.id, {