Can not paste a single image from Word doc or local folder

#1

When pasting image copied from OS folder (like literally ctrl + c, ctrl +v, not dropping) I get nothing in editor. When debugging I found a place in code (prosemirror-view/src/input.js, doPaste function) which, when pasting, doesn't consider attached images:

function doPaste(view, text, html, e) {
    let slice = parseFromClipboard(view, text, html, view.shiftKey, view.state.selection.$from) 
    if (!slice) return false 

    if (view.someProp("handlePaste", f => f(view, e, slice))) return true
    ...

However it lets me add my custom handlePaste prop to a plugin which checks for attached images and can insert them into the doc. slice here is non null, since when copying image in OS folder it, besides attaching a file also adds the name of the file to the clipboardData prop of event, which goes in this function as an text param. Seems to be a workaround.

But when pasting an image copied from Word doc, there is no file name added to the clipboardData, and the workaround I've mentioned above doesn't work. doPaste just returns false since slice is null. In this case even adding custom handlePaste prop doesn't help - it just doesn't get to that line.

Am I doing something wrong or it requires a patch? Thanks.

0 Likes

#2

That was unintentional—this patch makes it so that the prop is called even when slice is null. Does that work for you?

1 Like

#3

Yes, this definitely will work for me! Thanks a lot. Sorry for dumb question, but how it usually works - when this patch will be available in ProseMirror?

0 Likes

#4

Was waiting for your confirmation—I’ve released prosemirror-view 1.8.7 with the fix.

0 Likes