Skip to content

Commit

Permalink
fix(sheets): save text editor style (#4570)
Browse files Browse the repository at this point in the history
  • Loading branch information
weird94 authored Jan 25, 2025
1 parent 1a8981d commit 3059f03
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
7 changes: 3 additions & 4 deletions packages/core/src/docs/data-model/rich-text-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/docs-ui/src/basics/paragraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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--) {
Expand Down
7 changes: 3 additions & 4 deletions packages/docs-ui/src/commands/commands/ime-input.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export interface IIMEInputCommandParams {
isCompositionEnd: boolean;
}

const UNITS = SHEET_EDITOR_UNITS;

export const IMEInputCommand: ICommand<IIMEInputCommandParams> = {
id: 'doc.command.ime-input',

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 3059f03

Please sign in to comment.