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 become rich text when end edit (#4309)

ybzkyd57f88b9dad2
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 c390d4733c..33db40272e 100644
--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
@@ -289,9 +289,9 @@ export class EditingRenderController extends Disposable implements IRenderModule
}));
}
- /**
- * Listen to document edits to refresh the size of the sheet editor, not for normal editor.
- */
+ /**
+ * Listen to document edits to refresh the size of the sheet editor, not for normal editor.
+ */
private _commandExecutedListener(d: DisposableCollection) {
const updateCommandList = [RichTextEditingMutation.id];
@@ -829,13 +829,14 @@ export function getCellDataByInput(
export function isRichText(body: IDocumentBody): boolean {
const { textRuns = [], paragraphs = [], customRanges, customBlocks = [] } = body;
- const bodyNoLineBreak = body.dataStream.replace('\r\n', '');
+ const bodyNoLineBreak = body.dataStream.replace(/(\r\n)+$/, '');
// Some styles are unique to rich text. When this style appears, we consider the value to be rich text.
const richTextStyle = ['va'];
return (
- textRuns.some((textRun) => {
+ // This is because after editing, an inexplicable second paragraph style will appear \r\n
+ textRuns.filter((ts) => ts.st < bodyNoLineBreak.length).some((textRun) => {
const hasRichTextStyle = Boolean(textRun.ts && Object.keys(textRun.ts).some((property) => {
return richTextStyle.includes(property);
}));