Skip to content

Commit c2ef637

Browse files
committed
restore 1.9.0 different row/col behaviour
1 parent 822e54d commit c2ef637

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/Sortable.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ let dragEl,
201201
);
202202
},
203203

204+
_dragElInRowColumn = function(dragRect, targetRect, vertical) {
205+
let dragElS1Opp = vertical ? dragRect.left : dragRect.top,
206+
dragElS2Opp = vertical ? dragRect.right : dragRect.bottom,
207+
dragElOppLength = vertical ? dragRect.width : dragRect.height,
208+
targetS1Opp = vertical ? targetRect.left : targetRect.top,
209+
targetS2Opp = vertical ? targetRect.right : targetRect.bottom,
210+
targetOppLength = vertical ? targetRect.width : targetRect.height;
211+
212+
return (
213+
dragElS1Opp === targetS1Opp ||
214+
dragElS2Opp === targetS2Opp ||
215+
(dragElS1Opp + dragElOppLength / 2) === (targetS1Opp + targetOppLength / 2)
216+
);
217+
},
218+
204219
/**
205220
* Detects first nearest empty sortable to X and Y position using emptyInsertThreshold.
206221
* @param {Number} x X position
@@ -963,7 +978,7 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
963978
target,
964979
completed,
965980
onMove(target, after) {
966-
onMove(rootEl, el, dragEl, dragRect, target, getRect(target), evt, after);
981+
return onMove(rootEl, el, dragEl, dragRect, target, getRect(target), evt, after);
967982
},
968983
changed,
969984
...extra
@@ -1137,23 +1152,25 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
11371152
}
11381153
}
11391154
else if (target.parentNode === el) {
1155+
targetRect = getRect(target);
11401156
let direction = 0,
11411157
targetBeforeFirstSwap,
11421158
differentLevel = dragEl.parentNode !== el,
1159+
differentRowCol = !_dragElInRowColumn(dragEl.animated && dragEl.toRect || dragRect, target.animated && target.toRect || targetRect, vertical),
11431160
side1 = vertical ? 'top' : 'left',
11441161
scrolledPastTop = isScrolledPast(target, null, 'top', 'top') || isScrolledPast(dragEl, null, 'top', 'top'),
11451162
scrollBefore = scrolledPastTop ? scrolledPastTop.scrollTop : void 0;
11461163

11471164

11481165
if (lastTarget !== target) {
1149-
targetBeforeFirstSwap = getRect(target)[side1];
1166+
targetBeforeFirstSwap = targetRect[side1];
11501167
pastFirstInvertThresh = false;
1151-
isCircumstantialInvert = options.invertSwap || differentLevel;
1168+
isCircumstantialInvert = (!differentRowCol && options.invertSwap) || differentLevel;
11521169
}
11531170

11541171
direction = _getSwapDirection(
11551172
evt, target, vertical,
1156-
options.swapThreshold,
1173+
differentRowCol ? 1 : options.swapThreshold,
11571174
options.invertedSwapThreshold == null ? options.swapThreshold : options.invertedSwapThreshold,
11581175
isCircumstantialInvert,
11591176
lastTarget === target
@@ -1182,8 +1199,6 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
11821199

11831200
lastDirection = direction;
11841201

1185-
targetRect = getRect(target);
1186-
11871202
let nextSibling = target.nextElementSibling,
11881203
after = false;
11891204

0 commit comments

Comments
 (0)