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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: not escape when copy content (#2354)
ybzkyc10e4d93e399
diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.tsindex a9f242246b..5eb09a2000 100644--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts@@ -1060,8 +1060,7 @@ function getMatrixPlainText(matrix: ObjectMatrix<ICellDataWithSpanInfo>) {}function getCellTextForClipboard(cell: ICellDataWithSpanInfo) {- const formatValue = extractPureTextFromCell(cell);- return escapeSpecialCode(formatValue?.toString() || '');+ return extractPureTextFromCell(cell);}export const escapeSpecialCode = (cellStr: string) =>diff --git a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.tsindex 9ac5ba6dfc..5d20bccbe8 100644--- a/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts+++ b/packages/sheets-ui/src/services/clipboard/html-to-usm/converter.ts@@ -119,6 +119,7 @@ export class HtmlToUSMService {hideIframe(this._htmlElement);}+ // eslint-disable-next-line max-lines-per-functionconvert(html: string): IUniverSheetCopyDataModel {if (this._htmlElement.contentDocument) {this._htmlElement.contentDocument.open();@@ -190,13 +191,23 @@ export class HtmlToUSMService {textRuns,paragraphs: generateParagraphs(singleDataStream),};- const p = this._generateDocumentDataModelSnapshot({- body: singleDocBody,- });- valueMatrix.setValue(0, 0, {- v: dataStream,- p,- });++ const dataStreamLength = dataStream.length;+ const textRunsLength = textRuns?.length ?? 0;+ if (!textRunsLength || (textRunsLength === 1 && textRuns![0].st === 0 && textRuns![0].ed === dataStreamLength)) {+ valueMatrix.setValue(0, 0, {+ v: dataStream,+ });+ } else {+ const p = this._generateDocumentDataModelSnapshot({+ body: singleDocBody,+ });+ valueMatrix.setValue(0, 0, {+ v: dataStream,+ p,+ });+ }+rowProperties.push({}); // TODO@yuhongz}}diff --git a/packages/sheets-ui/src/services/clipboard/usm-to-html/convertor.ts b/packages/sheets-ui/src/services/clipboard/usm-to-html/convertor.tsindex e37bcc4919..da3f21122b 100644--- a/packages/sheets-ui/src/services/clipboard/usm-to-html/convertor.ts+++ b/packages/sheets-ui/src/services/clipboard/usm-to-html/convertor.ts@@ -17,6 +17,7 @@import type { ICellData, IRange, ObjectMatrix } from '@univerjs/core';import type { ICellDataWithSpanInfo, IClipboardPropertyItem, ISheetClipboardHook } from '../type';+import { escapeSpecialCode } from '../clipboard.service';/***@@ -75,8 +76,9 @@ function getTDContent(const mergedProperties = mergeProperties(properties);const str = zipClipboardPropertyItemToString(mergedProperties);const content = hooks.reduce((acc, hook) => acc || hook.onCopyCellContent?.(row, col) || '', '');+ const escapedContent = escapeSpecialCode(content);- return `<td${str}>${content}</td>`;+ return `<td${str}>${escapedContent}</td>`;}function getColStyle(cols: number[], hooks: ISheetClipboardHook[]) {