grid
                                
                                 grid copied to clipboard
                                
                                    grid copied to clipboard
                            
                            
                            
                        Finding new position is triggered too late in jQuery plugin when only having one lane
When there is only one lane in the grid, finding a new position for items is triggered too late when using the jQuery plugin. It works fine with the first item next to the one that is dragged, but the second already has a wrong "trigger point" - it looks like the dimensions of the item underneath the dragged one are calculated incorrectly (one cell falsely added).
This only happens when moving an item left to right (horizontal grid) or top to bottom (vertical grid) and not in the other direction.
Here you can see the behavior (please ignore the strange image jumping in the beginning):

The problem lies in how we rebuild the grid when we can't reposition the items underneath the dragged item. What happens is the following:
- You drag 0over2.
- We empty 0current spot and place it on the new position.
- The grid now looks like empty spot | 1 | 0, 2 | 3, | 4 | etc
- We see that 0collides with2and try to move2around.
- By moving 2around it collides with1or3.
- Solving collisions has failed so we need to rebuild the grid.
- We sort all the items trying to preserve columns.
- The items are now 1 | 0 | 2 | 3 | 4 | etc. <- when 2 items have the same positions we order them by their index.
- We place 0in the desired position (x = 2, y = 0).
- We start looking for a spot for 1.
- It's the first item in the sorted list so we put it at x = 0, y = 0.
- We start looking for a spot for 2.
- We try to preserve its previous horizontal position so we start comparing it with the items we've placed so far.
- We compare it with 1and we decide it should sit after it.
- We compare it with 0and we decide it should sit after it. <- because0comes before2in the list.
- No more items to compare to so we place it at x = 3, y = 0.
- We place the other items after x = 3.
- We finish placing all the items. Now they look like 1 | empty spot | 0 | 2 | 3 | 4 | etc.
- We pull the items to the left to get rid of empty spots.
- The final list looks like 1 | 0 | 2 | 3 | 4 | etc.
There's no easy fix for this without redoing our positioning algorithm.
/cc @ovidiu-chereches-hs
I see. Thank you for pointing it out!