@@ -178,6 +178,11 @@ export class SideMenuView<
178
178
this . onDrop as EventListener ,
179
179
true
180
180
) ;
181
+ this . pmView . root . addEventListener (
182
+ "dragend" ,
183
+ this . onDragEnd as EventListener ,
184
+ true
185
+ ) ;
181
186
initializeESMDependencies ( ) ;
182
187
183
188
// Shows or updates menu position whenever the cursor moves, if the menu isn't frozen.
@@ -300,8 +305,8 @@ export class SideMenuView<
300
305
// a block from a different editor is being dropped, this causes some
301
306
// issues that the code below fixes:
302
307
if ( ! this . isDragOrigin && this . pmView . dom === parentEditorElement ) {
303
- // 1. Because the editor selection is unrelated to the dragged content,
304
- // we don't want PM to delete its content. Therefore, we collapse the
308
+ // Because the editor selection is unrelated to the dragged content, we
309
+ // don't want PM to delete its content. Therefore, we collapse the
305
310
// selection.
306
311
this . pmView . dispatch (
307
312
this . pmView . state . tr . setSelection (
@@ -312,8 +317,8 @@ export class SideMenuView<
312
317
)
313
318
) ;
314
319
} else if ( this . isDragOrigin && this . pmView . dom !== parentEditorElement ) {
315
- // 2. Because the editor from which the block originates doesn't get a
316
- // drop event on it, PM doesn't delete its selected content. Therefore, we
320
+ // Because the editor from which the block originates doesn't get a drop
321
+ // event on it, PM doesn't delete its selected content. Therefore, we
317
322
// need to do so manually.
318
323
//
319
324
// Note: Deleting the selected content from the editor from which the
@@ -328,11 +333,6 @@ export class SideMenuView<
328
333
0
329
334
) ;
330
335
}
331
- // 3. PM only clears `view.dragging` on the editor that the block was
332
- // dropped, so we manually have to clear it on all the others. However,
333
- // PM also needs to read `view.dragging` while handling the event, so we
334
- // use a `setTimeout` to ensure it's only cleared after that.
335
- setTimeout ( ( ) => ( this . pmView . dragging = null ) , 0 ) ;
336
336
}
337
337
338
338
if (
@@ -360,6 +360,14 @@ export class SideMenuView<
360
360
}
361
361
} ;
362
362
363
+ onDragEnd = ( ) => {
364
+ // When the user starts dragging a block, `view.dragging` is set on all
365
+ // BlockNote editors. However, when the drag ends, only the editor that the
366
+ // drag originated in automatically clears `view.dragging`. Therefore, we
367
+ // have to manually clear it on all editors.
368
+ this . pmView . dragging = null ;
369
+ } ;
370
+
363
371
/**
364
372
* If a block is being dragged, ProseMirror usually gets the context of what's
365
373
* being dragged from `view.dragging`, which is automatically set when a
@@ -580,6 +588,11 @@ export class SideMenuView<
580
588
this . onDrop as EventListener ,
581
589
true
582
590
) ;
591
+ this . pmView . root . removeEventListener (
592
+ "dragend" ,
593
+ this . onDragEnd as EventListener ,
594
+ true
595
+ ) ;
583
596
this . pmView . root . removeEventListener (
584
597
"keydown" ,
585
598
this . onKeyDown as EventListener ,
0 commit comments