@@ -1175,7 +1175,7 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
1175
1175
return completed ( false ) ;
1176
1176
}
1177
1177
1178
- // assign target only if condition is true
1178
+ // if there is a last element, it is the target
1179
1179
if ( elLastChild && el === evt . target ) {
1180
1180
target = elLastChild ;
1181
1181
}
@@ -1193,6 +1193,23 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
1193
1193
return completed ( true ) ;
1194
1194
}
1195
1195
}
1196
+ else if ( elLastChild && _ghostIsFirst ( evt , vertical , this ) ) {
1197
+ let firstChild = getChild ( el , 0 , options , true ) ;
1198
+ if ( firstChild === dragEl ) {
1199
+ return completed ( false ) ;
1200
+ }
1201
+ target = firstChild ;
1202
+ targetRect = getRect ( target ) ;
1203
+
1204
+ if ( onMove ( rootEl , el , dragEl , dragRect , target , targetRect , evt , false ) !== false ) {
1205
+ capture ( ) ;
1206
+ el . insertBefore ( dragEl , firstChild ) ;
1207
+ parentEl = el ; // actualization
1208
+
1209
+ changed ( ) ;
1210
+ return completed ( true ) ;
1211
+ }
1212
+ }
1196
1213
else if ( target . parentNode === el ) {
1197
1214
targetRect = getRect ( target ) ;
1198
1215
let direction = 0 ,
@@ -1762,6 +1779,14 @@ function _unsilent() {
1762
1779
_silent = false ;
1763
1780
}
1764
1781
1782
+ function _ghostIsFirst ( evt , vertical , sortable ) {
1783
+ let rect = getRect ( getChild ( sortable . el , 0 , sortable . options ) ) ;
1784
+ const spacer = 10 ;
1785
+
1786
+ return vertical ?
1787
+ ( ( evt . clientX < rect . left - spacer ) || ( evt . clientY < rect . top && evt . clientX < rect . right ) ) :
1788
+ ( ( evt . clientY < rect . top - spacer ) || ( evt . clientY < rect . bottom && evt . clientX < rect . left ) )
1789
+ }
1765
1790
1766
1791
function _ghostIsLast ( evt , vertical , sortable ) {
1767
1792
let rect = getRect ( lastChild ( sortable . el , sortable . options . draggable ) ) ;
0 commit comments