Skip to content

Commit

Permalink
поправил paste
Browse files Browse the repository at this point in the history
  • Loading branch information
veglem committed May 31, 2024
1 parent 8bfdcc7 commit 5192350
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions public/src/components/Editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 5192350

Please sign in to comment.