I went through the docs, the forum and couldn’t find the answer. I am trying to implement a Drag&Drop feature for Widget Decorations.
I have made the widget dom draggable and set the dropCursor extension in my cm configuration. My approach would to read the dropped cursor effect that the dropCursor dispatches and use that to move my widget, but two issues arise:
The drop event is not triggered on the editor when I drag and drop the widget to a new position. That does happen when doing so with a normal text.
Even if I manage to listen to this event, I would need to read the transaction effect from cursorDrop and I don’t see how.
In short, I want to drag a widget and when dropped read the cursorDrop anchor position, then dispatch the widget update.
PD: I know how time consuming is maintaing such a project and I really appreciated it.
You can add a dragstart handler on the widget, and do event.dataTransfer.setData("text/plain", ...) in your handler to set the content. (dragstart doesn’t propagate, so the editor’s drag handler doesn’t even fire in this situation)
@marijn I managed to make it work as you suggested, thanks, but the widget it being copied instead of moved. Meaning the decoration text is copied in the droped position duplicating the widget and I am wondering how to then remove the previous one or if there is something I am missing, again.
Looking at this more closely, it seems that dragstartdoes bubble, and there’s a better solution for this. With the patch below, you should be able to set up your widget so that its ignoreEvent method returns false for dragstart events, and the editor’s built-in implementation should ‘just work’ with drags of that widget.