@@ -1175,7 +1175,7 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
11751175 return completed ( false ) ;
11761176 }
11771177
1178- // assign target only if condition is true
1178+ // if there is a last element, it is the target
11791179 if ( elLastChild && el === evt . target ) {
11801180 target = elLastChild ;
11811181 }
@@ -1193,6 +1193,23 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
11931193 return completed ( true ) ;
11941194 }
11951195 }
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+ }
11961213 else if ( target . parentNode === el ) {
11971214 targetRect = getRect ( target ) ;
11981215 let direction = 0 ,
@@ -1762,6 +1779,14 @@ function _unsilent() {
17621779 _silent = false ;
17631780}
17641781
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+ }
17651790
17661791function _ghostIsLast ( evt , vertical , sortable ) {
17671792 let rect = getRect ( lastChild ( sortable . el , sortable . options . draggable ) ) ;
0 commit comments