@@ -312,7 +312,7 @@ Item {
312312    }
313313
314314    function  isValidDropPosition (dropIndex ) {
315-         //  Prevent dropping on labels, config, cycler, and  display items
315+         //  Prevent dropping on labels, config, cycler, or  display items
316316        var  item =  slotModel .get (dropIndex);
317317        if  (item .type  !==  " toggle" 
318318            return  false ;
@@ -321,6 +321,11 @@ Item {
321321        var  sliderLabelIndex =  findSliderLabelIndex ();
322322        var  optionsIndex =  findOptionsLabelIndex ();
323323
324+         //  Prevent dropping in invalid sections
325+         if  (dropIndex ===  0  ||  dropIndex ===  sliderLabelIndex ||  dropIndex >=  optionsIndex) {
326+             return  false ;
327+         }
328+ 
324329        //  Prevent dropping below unavailable toggles
325330        var  toggleSection =  dropIndex <  sliderLabelIndex ?  " fixed" :  " slider" 
326331        var  sectionStart =  toggleSection ===  " fixed" ?  1  :  sliderLabelIndex +  1 ;
@@ -338,7 +343,7 @@ Item {
338343            }
339344        }
340345
341-         //  If there's an unavailable toggle in this section and we're trying to drop below it 
346+         //  Allow dropping at or before the last available toggle 
342347        if  (firstUnavailableIndex !==  - 1  &&  dropIndex >=  firstUnavailableIndex) {
343348            return  false ;
344349        }
@@ -426,12 +431,12 @@ Item {
426431
427432    function  abortDrag () {
428433        if  (draggedItemIndex !==  - 1 ) {
429-             restoreOriginalOrder ();
434+             draggedItemIndex =  - 1 ;
435+             targetIndex =  - 1 ;
436+             dragProxy .visible  =  false ;
437+             autoScrollTimer .scrollSpeed  =  0 ;
438+             slotList .forceLayout ();
430439        }
431-         draggedItemIndex =  - 1 ;
432-         targetIndex =  - 1 ;
433-         dragProxy .visible  =  false ;
434-         autoScrollTimer .scrollSpeed  =  0 ;
435440    }
436441
437442    ListView {
@@ -794,11 +799,13 @@ Item {
794799                                var  optionsIndex =  findOptionsLabelIndex ();
795800                                var  sliderLabelIndex =  findSliderLabelIndex ();
796801
797-                                 //  Handle drop position calculation
798-                                 if  (dropIndex !==  draggedItemIndex && 
799-                                     dropIndex !==  sliderLabelIndex && 
800-                                     dropIndex <  optionsIndex) {
802+                                 //  Adjust dropIndex for the last position in the sliding row
803+                                 if  (dropIndex >  sliderLabelIndex &&  dropIndex >=  optionsIndex -  1 ) {
804+                                     //  If dropping below the last toggle, set dropIndex to the last valid toggle position
805+                                     dropIndex =  optionsIndex -  1 ;
806+                                 }
801807
808+                                 if  (dropIndex !==  draggedItemIndex &&  isValidDropPosition (dropIndex)) {
802809                                    var  targetY =  itemUnder .y  +  itemUnder .height  /  2 ;
803810                                    if  (dropY <  targetY &&  dropIndex >  0 ) {
804811                                        var  prevItem =  slotModel .get (dropIndex -  1 );
@@ -809,7 +816,6 @@ Item {
809816                                        }
810817                                    }
811818
812-                                     //  Check if valid before setting targetIndex
813819                                    if  (isValidDropPosition (dropIndex) &&  dropIndex !==  targetIndex) {
814820                                        targetIndex =  dropIndex;
815821                                        moveItems ();
@@ -836,15 +842,22 @@ Item {
836842                                var  optionsIndex =  findOptionsLabelIndex ();
837843                                var  sliderLabelIndex =  findSliderLabelIndex ();
838844
839-                                 if  ( dropIndex !==  draggedItemIndex  && 
840-                                      dropIndex <  optionsIndex && 
841-                                     dropIndex !==  sliderLabelIndex  && 
842-                                      isValidDropPosition (dropIndex)) { 
845+                                 //  Adjust  dropIndex for the last position in the sliding row 
846+                                 if  (dropIndex  >  sliderLabelIndex  &&   dropIndex >=  optionsIndex -   1 ) { 
847+                                     dropIndex =  optionsIndex  -   1 ; 
848+                                 } 
843849
850+                                 if  (dropIndex !==  draggedItemIndex &&  isValidDropPosition (dropIndex)) {
844851                                    targetIndex =  dropIndex;
845852                                    moveItems ();
853+                                 } else  {
854+                                     abortDrag ();
846855                                }
856+                             } else  {
857+                                 abortDrag ();
847858                            }
859+                         } else  {
860+                             abortDrag ();
848861                        }
849862
850863                        dragProxy .visible  =  false ;
0 commit comments