From 40c727df3c6057cab06335d9db76226c2f994020 Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 15 Sep 2023 18:00:34 +0700 Subject: [PATCH] Fix duplicated text when drag text from web browser inside editor --- lib/assets/summernote-lite-v2.min.js | 52 +++++++++++++++++++++------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/assets/summernote-lite-v2.min.js b/lib/assets/summernote-lite-v2.min.js index 4750dcaa..78841409 100644 --- a/lib/assets/summernote-lite-v2.min.js +++ b/lib/assets/summernote-lite-v2.min.js @@ -2788,19 +2788,45 @@ t.$dropzone.removeClass("hover"), n.text(t.lang.image.dragImageHere) })), this.$dropzone.on("drop", (function(e) { var n = e.originalEvent.dataTransfer; - e.preventDefault(), n && n.files && n.files.length ? (t.$editable.focus(), t.context.invoke("editor.insertImagesOrCallback", n.files)) : i.a.each(n.types, (function(e, o) { - if(!(o.toLowerCase().indexOf("_moz_") > -1)) { - var r = n.getData(o); - if(o.toLowerCase().indexOf("text") > -1) { - let modifiedText = r.replace(/(?:\r\n|\r|\n)/g, '
'); - t.context.invoke("editor.pasteHTML", modifiedText); - } else { - i()(r).each((function(e, n) { - t.context.invoke("editor.insertNode", n) - })); - } - } - })) + e.preventDefault(); + if (n && n.files && n.files.length) { + t.$editable.focus(); + t.context.invoke("editor.insertImagesOrCallback", n.files); + } else if (n && n.types && n.types.length) { + let indexTypeHtml = n.types.indexOf("text/html"); + if (indexTypeHtml > -1) { + const newTypes = n.types.filter(type => { + return type !== "text/plain"; + }); + + i.a.each(newTypes, (function(e, o) { + if (!(o.toLowerCase().indexOf("_moz_") > -1)) { + var r = n.getData(o); + if (o.toLowerCase().indexOf("text") > -1) { + t.context.invoke("editor.pasteHTML", r); + } else { + i()(r).each((function(e, n) { + t.context.invoke("editor.insertNode", n) + })); + } + } + })); + } else { + i.a.each(n.types, (function(e, o) { + if (!(o.toLowerCase().indexOf("_moz_") > -1)) { + var r = n.getData(o); + if (o.toLowerCase().indexOf("text") > -1) { + let modifiedText = r.replace(/(?:\r\n|\r|\n)/g, '
'); + t.context.invoke("editor.pasteHTML", modifiedText); + } else { + i()(r).each((function(e, n) { + t.context.invoke("editor.insertNode", n) + })); + } + } + })); + } + } })).on("dragover", !1) } }, {