@@ -39,6 +39,27 @@ define(function (require, exports, module) {
3939 let scrollInterval = null ;
4040 let dragSourcePane = null ;
4141
42+ /**
43+ * this function is responsible to make sure that all the drag state is properly cleaned up
44+ * it is needed to make sure that the tab bar doesn't get unresponsive
45+ * because of handlers not being attached properly
46+ */
47+ function cleanupDragState ( ) {
48+ $ ( ".tab" ) . removeClass ( "dragging drag-target" ) ;
49+ $ ( ".empty-pane-drop-target" ) . removeClass ( "empty-pane-drop-target" ) ;
50+ updateDragIndicator ( null ) ;
51+ draggedTab = null ;
52+ dragOverTab = null ;
53+ dragSourcePane = null ;
54+
55+ if ( scrollInterval ) {
56+ clearInterval ( scrollInterval ) ;
57+ scrollInterval = null ;
58+ }
59+
60+ $ ( "#tab-drag-extended-zone" ) . remove ( ) ;
61+ }
62+
4263 /**
4364 * Initialize drag and drop functionality for tab bars
4465 * This is called from `main.js`
@@ -202,9 +223,6 @@ define(function (require, exports, module) {
202223 if ( e . preventDefault ) {
203224 e . preventDefault ( ) ;
204225 }
205- // hide the drag indicator
206- updateDragIndicator ( null ) ;
207- removeOuterDropZone ( ) ;
208226
209227 // get container dimensions to determine drop position
210228 const containerRect = this . getBoundingClientRect ( ) ;
@@ -235,6 +253,9 @@ define(function (require, exports, module) {
235253 }
236254 }
237255 }
256+
257+ // ensure all drag state is cleaned up
258+ cleanupDragState ( ) ;
238259 } ) ;
239260
240261 /**
@@ -311,9 +332,7 @@ define(function (require, exports, module) {
311332 }
312333 }
313334
314- // Clean up
315- updateDragIndicator ( null ) ;
316- removeOuterDropZone ( ) ;
335+ cleanupDragState ( ) ;
317336 }
318337 }
319338
@@ -449,7 +468,6 @@ define(function (require, exports, module) {
449468 if ( e . stopPropagation ) {
450469 e . stopPropagation ( ) ; // Stops browser from redirecting
451470 }
452- updateDragIndicator ( null ) ;
453471
454472 // Only process the drop if the dragged tab is different from the drop target
455473 if ( draggedTab !== this ) {
@@ -474,6 +492,8 @@ define(function (require, exports, module) {
474492 moveWorkingSetItem ( targetPaneId , draggedPath , targetPath , onLeftSide ) ;
475493 }
476494 }
495+
496+ cleanupDragState ( ) ;
477497 return false ;
478498 }
479499
@@ -484,20 +504,7 @@ define(function (require, exports, module) {
484504 * @param {Event } e - The event object
485505 */
486506 function handleDragEnd ( e ) {
487- $ ( ".tab" ) . removeClass ( "dragging drag-target" ) ;
488- updateDragIndicator ( null ) ;
489- draggedTab = null ;
490- dragOverTab = null ;
491- dragSourcePane = null ;
492-
493- // Clear scroll interval if it exists
494- if ( scrollInterval ) {
495- clearInterval ( scrollInterval ) ;
496- scrollInterval = null ;
497- }
498-
499- // Remove the extended drop zone if it exists
500- $ ( "#tab-drag-extended-zone" ) . remove ( ) ;
507+ cleanupDragState ( ) ;
501508 }
502509
503510 /**
@@ -762,11 +769,7 @@ define(function (require, exports, module) {
762769 }
763770 }
764771
765- // reset all drag state stuff
766- updateDragIndicator ( null ) ;
767- draggedTab = null ;
768- dragOverTab = null ;
769- dragSourcePane = null ;
772+ cleanupDragState ( ) ;
770773 }
771774 } ) ;
772775 }
0 commit comments