From 6b6e70f02c0447bc625ae626f2bc2f48688b04c2 Mon Sep 17 00:00:00 2001 From: QiShaoXuan Date: Mon, 29 Aug 2022 11:26:01 +0800 Subject: [PATCH] fix: can not copy text other than block --- .../src/editor/clipboard/clipboardEventDispatcher.ts | 12 ++++++------ .../src/editor/clipboard/clipboardUtils.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libs/components/editor-core/src/editor/clipboard/clipboardEventDispatcher.ts b/libs/components/editor-core/src/editor/clipboard/clipboardEventDispatcher.ts index a4f0c76044..675b1d603f 100644 --- a/libs/components/editor-core/src/editor/clipboard/clipboardEventDispatcher.ts +++ b/libs/components/editor-core/src/editor/clipboard/clipboardEventDispatcher.ts @@ -72,21 +72,21 @@ export class ClipboardEventDispatcher { ); } - private _copyHandler(e: ClipboardEvent) { - if (!this._utils.shouldHandlerContinue(e)) { + private async _copyHandler(e: ClipboardEvent) { + if (!(await this._utils.shouldHandlerContinue(e))) { return; } this._editor.getHooks().onCopy(e); } - private _cutHandler(e: ClipboardEvent) { - if (!this._utils.shouldHandlerContinue(e)) { + private async _cutHandler(e: ClipboardEvent) { + if (!(await this._utils.shouldHandlerContinue(e))) { return; } this._editor.getHooks().onCut(e); } - private _pasteHandler(e: ClipboardEvent) { - if (!this._utils.shouldHandlerContinue(e)) { + private async _pasteHandler(e: ClipboardEvent) { + if (!(await this._utils.shouldHandlerContinue(e))) { return; } diff --git a/libs/components/editor-core/src/editor/clipboard/clipboardUtils.ts b/libs/components/editor-core/src/editor/clipboard/clipboardUtils.ts index 09c532273c..2b93912d67 100644 --- a/libs/components/editor-core/src/editor/clipboard/clipboardUtils.ts +++ b/libs/components/editor-core/src/editor/clipboard/clipboardUtils.ts @@ -11,7 +11,7 @@ export class ClipboardUtils { this._editor = editor; } - shouldHandlerContinue(event: ClipboardEvent) { + async shouldHandlerContinue(event: ClipboardEvent) { const filterNodes = ['INPUT', 'SELECT', 'TEXTAREA']; if (event.defaultPrevented) { @@ -20,8 +20,12 @@ export class ClipboardUtils { if (filterNodes.includes((event.target as HTMLElement)?.tagName)) { return false; } + const selectInfo = await this._editor.selectionManager.getSelectInfo(); - return this._editor.selectionManager.currentSelectInfo.type !== 'None'; + return ( + selectInfo.blocks.length && + this._editor.selectionManager.currentSelectInfo.type !== 'None' + ); } async getClipInfoOfBlockById(blockId: string) {