Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/vls-65' into vls-65
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikMix committed May 31, 2024
2 parents 5fc05dd + 62102e7 commit 54e3baf
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions public/src/components/Editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 54e3baf

Please sign in to comment.