From 3dbff776c148a3b5d7440cfe5de9b68d5ecde014 Mon Sep 17 00:00:00 2001 From: yaolongfei <2991205548@qq.com> Date: Tue, 15 Oct 2024 11:46:08 +0800 Subject: [PATCH] fix: unable to copy text in read-only mode (#251) * style: refactor by eslint * fix: unable to copy text in read-only mode * Create nice-pens-kick.md --- .changeset/nice-pens-kick.md | 5 +++++ packages/core/src/text-area/event-handlers/copy.ts | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .changeset/nice-pens-kick.md diff --git a/.changeset/nice-pens-kick.md b/.changeset/nice-pens-kick.md new file mode 100644 index 000000000..0010d558b --- /dev/null +++ b/.changeset/nice-pens-kick.md @@ -0,0 +1,5 @@ +--- +"@wangeditor-next/core": patch +--- + +163 bug只读模式下无法复制文本内容 diff --git a/packages/core/src/text-area/event-handlers/copy.ts b/packages/core/src/text-area/event-handlers/copy.ts index 2b1a05271..58f5f9dca 100644 --- a/packages/core/src/text-area/event-handlers/copy.ts +++ b/packages/core/src/text-area/event-handlers/copy.ts @@ -4,18 +4,20 @@ */ import { IDomEditor } from '../../editor/interface' -// import { DomEditor } from '../../editor/dom-editor' -import TextArea from '../TextArea' import { hasEditableTarget } from '../helpers' +import TextArea from '../TextArea' -function handleOnCopy(e: Event, textarea: TextArea, editor: IDomEditor) { +function handleOnCopy(e: Event, _textarea: TextArea, editor: IDomEditor) { const event = e as ClipboardEvent - if (!hasEditableTarget(editor, event.target)) return - event.preventDefault() + if (!hasEditableTarget(editor, event.target)) { return } + const { readOnly } = editor.getConfig() + + if (!readOnly) { event.preventDefault() } const data = event.clipboardData - if (data == null) return + + if (data == null) { return } editor.setFragmentData(data) }