@@ -54,6 +54,7 @@ export class BlockTab extends Component {
54
54
onSnippetGroupClick ( snippet ) {
55
55
this . shared . operation . next (
56
56
async ( ) => {
57
+ this . cancelDragAndDrop = this . shared . history . makeSavePoint ( ) ;
57
58
let snippetEl ;
58
59
const baseSectionEl = snippet . content . cloneNode ( true ) ;
59
60
this . state . ongoingInsertion = true ;
@@ -101,6 +102,7 @@ export class BlockTab extends Component {
101
102
await this . processDroppedSnippet ( snippetEl ) ;
102
103
}
103
104
this . state . ongoingInsertion = false ;
105
+ delete this . cancelDragAndDrop ;
104
106
} ,
105
107
{ withLoadingEffect : false }
106
108
) ;
@@ -223,7 +225,12 @@ export class BlockTab extends Component {
223
225
} ,
224
226
{ withLoadingEffect : false }
225
227
) ;
226
- this . cancelDragAndDrop = this . shared . history . makeSavePoint ( ) ;
228
+ const restoreDragSavePoint = this . shared . history . makeSavePoint ( ) ;
229
+ this . cancelDragAndDrop = ( ) => {
230
+ // Undo the changes needed to ease the drag and drop.
231
+ this . dragState . restoreCallbacks ?. forEach ( ( restore ) => restore ( ) ) ;
232
+ restoreDragSavePoint ( ) ;
233
+ } ;
227
234
this . hideSnippetToolTip ?. ( ) ;
228
235
229
236
this . document . body . classList . add ( "oe_dropzone_active" ) ;
@@ -232,6 +239,14 @@ export class BlockTab extends Component {
232
239
this . dragState = { } ;
233
240
dropzoneEls = [ ] ;
234
241
242
+ // Make some changes on the page to ease the drag and drop.
243
+ const restoreCallbacks = [ ] ;
244
+ for ( const prepareDrag of this . env . editor . getResource ( "on_prepare_drag_handlers" ) ) {
245
+ const restore = prepareDrag ( ) ;
246
+ restoreCallbacks . push ( restore ) ;
247
+ }
248
+ this . dragState . restoreCallbacks = restoreCallbacks ;
249
+
235
250
const category = element . closest ( ".o_snippets_container" ) . id ;
236
251
const id = element . dataset . id ;
237
252
snippet = this . snippetModel . getSnippet ( category , id ) ;
@@ -338,17 +353,20 @@ export class BlockTab extends Component {
338
353
if ( closestDropzoneEl ) {
339
354
currentDropzoneEl = closestDropzoneEl ;
340
355
}
341
- } else {
342
- this . cancelDragAndDrop ( ) ;
343
356
}
344
357
}
345
358
346
359
if ( currentDropzoneEl ) {
347
360
currentDropzoneEl . after ( snippetEl ) ;
348
361
this . shared . dropzone . removeDropzones ( ) ;
349
362
363
+ // Undo the changes needed to ease the drag and drop.
364
+ this . dragState . restoreCallbacks . forEach ( ( restore ) => restore ( ) ) ;
365
+ this . dragState . restoreCallbacks = null ;
366
+
350
367
if ( ! isSnippetGroup ) {
351
368
await this . processDroppedSnippet ( snippetEl ) ;
369
+ delete this . cancelDragAndDrop ;
352
370
} else {
353
371
this . shared . operation . next (
354
372
async ( ) => {
@@ -357,13 +375,13 @@ export class BlockTab extends Component {
357
375
{ withLoadingEffect : false }
358
376
) ;
359
377
}
378
+ } else {
379
+ this . cancelDragAndDrop ( ) ;
380
+ delete this . cancelDragAndDrop ;
360
381
}
361
382
362
383
this . state . ongoingInsertion = false ;
363
384
delete this . cancelSnippetPreview ;
364
- if ( ! isSnippetGroup ) {
365
- delete this . cancelDragAndDrop ;
366
- }
367
385
dragAndDropResolve ( ) ;
368
386
} ,
369
387
} ;
@@ -382,7 +400,7 @@ export class BlockTab extends Component {
382
400
const cancel = await onSnippetDropped ( { snippetEl, dragState : this . dragState } ) ;
383
401
// Cancel everything if the resource asked to.
384
402
if ( cancel ) {
385
- this . cancelDragAndDrop ?. ( ) ;
403
+ this . cancelDragAndDrop ( ) ;
386
404
return ;
387
405
}
388
406
}
0 commit comments