From 51923502ced9d858c38a71cf9476e8f276cfac33 Mon Sep 17 00:00:00 2001 From: ZhurmilovVadim Date: Fri, 31 May 2024 22:41:55 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20paste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/src/components/Editor/Editor.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/public/src/components/Editor/Editor.ts b/public/src/components/Editor/Editor.ts index c49c0363..e47e1f00 100644 --- a/public/src/components/Editor/Editor.ts +++ b/public/src/components/Editor/Editor.ts @@ -36,14 +36,26 @@ export class Editor { this.addPlugins(); document.onpaste = (event) => { + const isInEditor = (node: Node) => { + if (node.nodeType === Node.ELEMENT_NODE && (node as HTMLElement).contentEditable === 'true' && !(node as HTMLElement).classList.contains("note-title")) { + return true + } else if (node.parentElement == null) { + return false + } else { + return isInEditor(node.parentElement); + } + } + event.preventDefault(); - let paste = (event.clipboardData).getData("text"); - const selection = window.getSelection(); - if (!selection.rangeCount) return; - selection.deleteFromDocument(); - selection.getRangeAt(0).insertNode(document.createTextNode(paste)); - selection.collapseToEnd(); + if (isInEditor(document.getSelection().anchorNode)) { + let paste = (event.clipboardData).getData("text"); + const selection = window.getSelection(); + if (!selection.rangeCount) return; + selection.deleteFromDocument(); + selection.getRangeAt(0).insertNode(document.createTextNode(paste)); + selection.collapseToEnd(); + } } this.editable = document.createElement('div'); From 62102e7d11acccb30c954ffb33eef75540b9d90a Mon Sep 17 00:00:00 2001 From: ZhurmilovVadim Date: Fri, 31 May 2024 22:51:54 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20paste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/src/components/Editor/Editor.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/src/components/Editor/Editor.ts b/public/src/components/Editor/Editor.ts index e47e1f00..21dc55a0 100644 --- a/public/src/components/Editor/Editor.ts +++ b/public/src/components/Editor/Editor.ts @@ -46,9 +46,10 @@ export class Editor { } } - event.preventDefault(); + if (isInEditor(document.getSelection().anchorNode)) { + event.preventDefault(); let paste = (event.clipboardData).getData("text"); const selection = window.getSelection(); if (!selection.rangeCount) return;