Example: nostalgic-sky-7wssh6 - CodeSandbox
I tried dragging a file into input area.
But only the dragenter
and dragover
events were triggered
Example: nostalgic-sky-7wssh6 - CodeSandbox
I tried dragging a file into input area.
But only the dragenter
and dragover
events were triggered
You donât seem to have a handler for drop
events. When I add that I can see them just fine.
I found a related topic, the example in it is as follows
view.scrollDOM.addEventListener('drop', (event) => {
event.preventDefault();
event.stopPropagation();
});
It works.
But wouldnât it work as an extension like this
const view = new EditorView({
doc: '',
parent: inputWrapperRef.value,
extensions: [
EditorView.domEventHandlers({
drag: (e) => {
console.log('drag', e);
},
}),
],
});
Youâre still adding a drag
handler, not a drop
handler.
Sorry, my fault. Thanks for your response
Seems useful to add my Q here instead of starting a new thread.
Any issues with drag/drop on MacOS? In case it matters: old Intel MacBook, still on 12.7.1 Monterey.
With initial attempt: dragging selected text actually dragged entire contents of doc!
With next attempt, below, the other events show up in console.log but âdropâ does not. Thoughts?
const dragAndDropExt = EditorView.domEventHandlers({
dragstart(e, _) {
let s = getCurrentSelection();
let data = { from: Math.min(s.from, s.to) };
console.log('dragstart', data);
e.dataTransfer.setData("text/object", JSON.stringify(data));
},
dragover(e, _) {
console.log('dragover');
e.preventDefault();
},
dragenter(e, _) {
console.log('dragenter');
e.preventDefault();
},
drop(e, _) {
console.log('drop: BEFORE getData');
let data = JSON.parse(e.dataTransfer.getData("text/object"));
console.log('drop', data);
},
});
@marijn It looks like âdropâ isnât reaching my code.
Any thoughts? Maybe a recent regression? Or something specific to my setup?
I canât reproduce what youâre seeing here. But also, the editor already has a drag/stop setup, so there is definitely no need to register all these drag events yourself.
Thanks for taking a look. Just to close the loop: the issue was specific to Tauri, with a simple workaround when setting up the window:
v1: âfileDropEnabledâ: false
v2: âdragDropEnabledâ: false