Rovak / InlineAttachment

Easily paste and upload files/images in plain textareas
http://git.razko.nl/InlineAttachment
MIT License
618 stars 77 forks source link

Drop to the coursor. #64

Open pahaz opened 8 years ago

pahaz commented 8 years ago

Hi. We use InlineAttacjment with CodeMirror 5.6.0.

When dropping file to the editor it drop to the previous coursor position (not to the line where we release mouse).

Do you know about this?

Is this a correct behavior?

Rovak commented 8 years ago

Hi Pahaz,

I was not aware of the issue, i will test it out and make a fix when i got the time

dae721 commented 6 years ago

I was able to work around the problem by adding a drop handler which repositions the cursor to the drop location when it detects a file is being dropped. Here's the typescript from our editor subclass, where this.cm is of type CodeMirror.Editor:

this.cm.on('drop', (editor, e: DragEvent) => {
    if (e.dataTransfer.files.length > 0) {
        let pos = this.cm.coordsChar({left: e.clientX, top: e.clientY}, 'window');
        this.cm.getDoc().setCursor(pos);
    }
});

This has to be done before the call to codemirror4.attach() so it gets called before the inlineAttachment drop handler.