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: paste should clear style when paste to editor in sheet (#3215)

ybzky781c72e8b374
diff --git a/packages/docs-ui/src/services/clipboard/clipboard.service.ts b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
index 9eb89d1d1a..b92a748dca 100644
--- a/packages/docs-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
@@ -15,7 +15,7 @@
*/
import type { DocumentDataModel, ICustomRange, IDisposable, IDocumentBody, IDocumentData, IParagraph, Nullable } from '@univerjs/core';
-import { createIdentifier, CustomRangeType, DataStreamTreeTokenType, Disposable, getBodySlice, ICommandService, ILogService, Inject, IUniverInstanceService, normalizeBody, SliceBodyType, toDisposable, Tools, UniverInstanceType } from '@univerjs/core';
+import { createIdentifier, CustomRangeType, DataStreamTreeTokenType, Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, getBodySlice, ICommandService, ILogService, Inject, IUniverInstanceService, normalizeBody, SliceBodyType, toDisposable, Tools, UniverInstanceType } from '@univerjs/core';
import { HTML_CLIPBOARD_MIME_TYPE, IClipboardInterfaceService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE } from '@univerjs/ui';
import { CutContentCommand, DocCustomRangeService, getCursorWhenDelete, getDeleteSelection, InnerPasteCommand, TextSelectionManagerService } from '@univerjs/docs';
@@ -132,6 +132,16 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
async legacyPaste(html?: string, text?: string): Promise<boolean> {
const partDocData = this._genDocDataFromHtmlAndText(html, text);
+ // Paste in sheet editing mode without paste style, so we give textRuns empty array;
+ if (this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)?.getUnitId() === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
+ if (text) {
+ const textDocData = this._generateBody(text);
+ return this._paste({ body: textDocData });
+ } else {
+ partDocData.body!.textRuns = [];
+ }
+ }
+
return this._paste(partDocData);
}
@@ -184,7 +194,7 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
];
return this._commandService.executeCommand(CutContentCommand.id, { segmentId, textRanges: newTextRanges });
- // eslint-disable-next-line unused-imports/no-unused-vars
+ // eslint-disable-next-line unused-imports/no-unused-vars
} catch (_e) {
this._logService.error('[DocClipboardController] cut content failed');
return false;