aboutsummaryrefslogtreecommitdiff
path: root/editor/editor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor.ts')
-rw-r--r--editor/editor.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/editor/editor.ts b/editor/editor.ts
index c7ce506..1ea0438 100644
--- a/editor/editor.ts
+++ b/editor/editor.ts
@@ -109,8 +109,22 @@ export class WuiEditor {
this.elContent.addEventListener("paste", (ev: ClipboardEvent) => {
ev.preventDefault();
- const text = ev.clipboardData?.getData("text/plain");
- document.execCommand("insertText", false, text);
+ let text: string = ev.clipboardData?.getData("text/plain") || "";
+ if (!text) {
+ console.error(`on paste: text is ${text}`);
+ return;
+ }
+ const selection = window.getSelection();
+ if (!selection || !selection.rangeCount) {
+ console.error(`on paste: failed to get selection`);
+ return;
+ }
+
+ text = text.trimEnd();
+ selection.deleteFromDocument();
+ selection.getRangeAt(0).insertNode(document.createTextNode(text));
+ selection.collapseToEnd();
+
this.renderLineNumber(this.getContent());
});