Skip to content

Commit 122be52

Browse files
committed
fix pasting
1 parent a6fa6bc commit 122be52

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

src/exports/elements/tip-tap-editor-base.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -714,36 +714,23 @@ export class TipTapEditorBase extends BaseElement {
714714
if (event == null) return;
715715

716716
const { clipboardData } = event;
717-
console.log(event)
718717

719718
if (clipboardData == null) return;
720719

721720
const hasFiles = clipboardData.files?.length > 0;
722721

723722
if (!hasFiles && clipboardData.items?.length > 0) {
724723
event.preventDefault();
725-
const data = clipboardData.items
726-
let promises: Promise<string>[] = []
727-
for (let i = 0; i < data.length; i += 1) {
728-
promises.push(new Promise<string>((resolve) => {
729-
const item = data[i]
730-
if (item.kind === "string" && item.type.match("^text")) {
731-
item.getAsString((str) => {
732-
resolve(str)
733-
})
734-
}
735-
}))
724+
725+
let dataType = "text/plain"
726+
727+
if (clipboardData.types.includes("text/html")) {
728+
dataType = "text/html"
736729
}
737730

738-
const strings: string[] = []
739-
const settledPromises = await Promise.allSettled(promises)
740-
settledPromises.forEach((promise) => {
741-
if (promise.status === "fulfilled") {
742-
strings.push(promise.value)
743-
}
744-
})
731+
const string = clipboardData.getData(dataType)
745732

746-
this.editor.chain().focus().insertContent(strings.join(" ")).run()
733+
this.editor.chain().focus().insertContent(string).run()
747734
return;
748735
}
749736

0 commit comments

Comments
 (0)