Drag and drop not working when dragging first element

Found strange block wrapping behavior when using dispatch and onmousedown.

My task is to implement a “Hook” to wrap block elements and use the standard drag mechanics.

The main logic is to add a widget in the form of a button using the plugin in decorations. When creating a button, I hang onmousedown on it

drag_action_button.onmousedown = () => {
    view.dispatch(view.state.tr.setSelection(NodeSelection.create(state.doc, pos)));
  };

The logic itself works correctly, except for one case: If you try to drag the first line, it does not react

If you remove dispatch and use a pre-allocated block for transfer, everything works correctly.

As an alternative, I wanted to use onmousemove. In this case, the transfer works as it should, but visually, at the moment of transferring the same first line, it looks like it transfers the entire editor, although in the end everything transfers correctly

What is the reason for this and how can it be corrected?

(gifs in the original post broke, so I’ll duplicate it here)

I think I have found the root of the problem, although it is not entirely obvious. The whole problem was in the position: absolute of the button. If you remove it - the first line is correctly transferred. That is, if the widget is the first in the document and position: absolute - it does not respond to drag&drop. One solution is to add a dummy widget at position 0, but this solution looks pretty messy. Maybe there is a better solution?