Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

findLeftMostPositionForItem logic is flawed #64

Merged
merged 1 commit into from
Aug 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/gridCollisionsSpec.js
Expand Up @@ -223,4 +223,24 @@ describe("Grid collisions", function() {
expectedItems[16] = {x: 9, y: 2};
expect(grid.items).toEqualPositions(expectedItems);
});

it("should check across the entire height of an item when searching for a " +
"position", function() {
var items = [
{x: 0, y: 2, w: 2, h: 2},
{x: 2, y: 1, w: 1, h: 2},
{x: 3, y: 1, w: 2, h: 2}
];

var grid = new GridList(GridList.cloneItems(items), {rows: 4});

helpers.addIndexesToItems(grid.items);
grid.moveItemToPosition(grid.items[2], [3, 0]);
helpers.sortItemsByIndex(grid.items);

var expectedItems = GridList.cloneItems(items);
expectedItems[2].y = 0;

expect(grid.items).toEqualPositions(expectedItems);
});
});
17 changes: 10 additions & 7 deletions src/gridList.js
Expand Up @@ -524,14 +524,17 @@ GridList.prototype = {
*/
var tail = 0,
otherItem,
i;
i, j;

for (i = 0; i < this.grid.length; i++) {
otherItem = this.grid[i][item.y];
if (!otherItem) {
continue;
}
if (this.items.indexOf(otherItem) < this.items.indexOf(item)) {
tail = otherItem.x + otherItem.w;
for (j = item.y; j < item.y + item.h; j++) {
otherItem = this.grid[i][j];
if (!otherItem) {
continue;
}
if (this.items.indexOf(otherItem) < this.items.indexOf(item)) {
tail = otherItem.x + otherItem.w;
}
}
}
return tail;
Expand Down