diff --git a/public/src/components/Editor/Editor.ts b/public/src/components/Editor/Editor.ts index c49c0363..21dc55a0 100644 --- a/public/src/components/Editor/Editor.ts +++ b/public/src/components/Editor/Editor.ts @@ -36,14 +36,27 @@ export class Editor { this.addPlugins(); document.onpaste = (event) => { - 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(); + 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); + } + } + + + + if (isInEditor(document.getSelection().anchorNode)) { + 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(); + } } this.editable = document.createElement('div');