UI Shaking When Dragging Grid with Larger or Equal Height into Another Grid
Description: I am encountering a UI issue with Gridstack when dragging a grid into another grid. If the height of the dragged grid is greater than or equal to the height of the dropped grid, the UI begins to shake uncontrollably when the dragged grid is close to the dropped grid.
Steps to Reproduce:
- Create two grids, one with a height greater than or equal to the other (e.g., draggedGridHeight >= droppedGridHeight).
- Initiate a drag operation on the larger grid.
- Drag it close to the smaller grid.
- Observe the rapid shaking of the UI.
Expected Behavior: The grids should align smoothly without any shaking, regardless of their relative heights.
Actual Behavior: The UI shakes uncontrollably when the dragged grid is close to the dropped grid.
oh that's gonna be fun to debug....
not seeing this issue with latest code. closing.
AI code, but not needed /** ms to sit on a 'leave to empty space' before acting on it, so a leave+re-enter pair caused by
- our own re-layout (rather than by the user moving) cancels out instead of shaking - see #2407 */ const leaveGrace = 30;
/** @internal a leave we haven't acted on yet. Taking an item into a grid resizes that grid (and
- removing it from the source shrinks THAT one), which shifts the layout out from under a
- stationary cursor and fires a leave - we then put everything back, it shifts again, we get an
- enter... every frame, which is the "UI shaking" in #2407. Sitting on the leave for a beat lets
- an immediate re-enter cancel it, so self-inflicted churn settles instead of oscillating. */ protected _leaveTimeout?: number;
protected _mouseEnter(e: MouseEvent): void {
// console.log(${count++} Enter ${this.el.id}); // TEST
this._cancelPendingLeave(); // back over us already - whatever moved under the cursor, stay put
...
protected _mouseLeave(e: MouseEvent, calledByEnter = false): void {
// console.log(${count++} Leave ${this.el.id}); // TEST
if (!DDManager.dragElement || DDManager.dropElement !== this) return;
e.preventDefault();
e.stopPropagation();
// Entering another grid already leaves us synchronously (see _mouseEnter), so only leaving to
// empty space waits - and that's exactly the case our own re-layout keeps faking (#2407).
if (!calledByEnter) {
this._cancelPendingLeave();
const ev = Utils.initEvent
/** @internal drop a leave we scheduled but haven't acted on */ protected _cancelPendingLeave(): void { if (this._leaveTimeout) { window.clearTimeout(this._leaveTimeout); delete this._leaveTimeout; } }
/** @internal the actual leave work, once we're sure the cursor really did go away */ protected _doMouseLeave(e: MouseEvent, calledByEnter: boolean): void { if (!DDManager.dragElement || DDManager.dropElement !== this) return;