diff --git a/src/main/java/codechicken/nei/BookmarkPanel.java b/src/main/java/codechicken/nei/BookmarkPanel.java index 78c1a33a..684a1cd7 100644 --- a/src/main/java/codechicken/nei/BookmarkPanel.java +++ b/src/main/java/codechicken/nei/BookmarkPanel.java @@ -574,7 +574,8 @@ public class BookmarkPanel extends PanelWidget { } else if (this.sortableGroup != null) { final int overRowIndex = Math.min(grid.getRowIndex(mousey), grid.getRows() - 1); - if (overRowIndex >= 0 && this.sortableGroup.groupId != this.grid.getRowGroupId(overRowIndex)) { + if (overRowIndex >= 0 && !isOverNamespaceControls(mousex, mousey) + && !this.sortableGroup.matches(this.grid, this.grid.getRowGroupId(overRowIndex))) { this.grid.moveGroup(this.sortableGroup, overRowIndex); } @@ -1022,14 +1023,18 @@ public class BookmarkPanel extends PanelWidget { this.mouseDownSlot = -1; } - @Override - public boolean onMouseWheel(int shift, int mousex, int mousey) { - - if ((!inEditingState() || this.sortableGroup != null) && new Rectangle4i( + private boolean isOverNamespaceControls(int mousex, int mousey) { + return new Rectangle4i( namespacePrev.x, namespacePrev.y, namespaceNext.x + namespaceNext.w - namespacePrev.x, - namespacePrev.h).contains(mousex, mousey)) { + namespacePrev.h).contains(mousex, mousey); + } + + @Override + public boolean onMouseWheel(int shift, int mousex, int mousey) { + + if ((!inEditingState() || this.sortableGroup != null) && isOverNamespaceControls(mousex, mousey)) { if (shift > 0) { this.storage.prevNamespace(); @@ -1108,7 +1113,7 @@ public class BookmarkPanel extends PanelWidget { final int overRowIndex = Math.min(grid.getRowIndex(mousey), grid.getRows() - 1); if (this.sortableGroup != null && overRowIndex >= 0 - && this.sortableGroup.groupId != this.grid.getRowGroupId(overRowIndex)) { + && !this.sortableGroup.matches(this.grid, this.grid.getRowGroupId(overRowIndex))) { this.grid.moveGroup(this.sortableGroup, overRowIndex); } diff --git a/src/main/java/codechicken/nei/bookmark/BookmarkGrid.java b/src/main/java/codechicken/nei/bookmark/BookmarkGrid.java index ecb7c4c1..04eb5e8f 100644 --- a/src/main/java/codechicken/nei/bookmark/BookmarkGrid.java +++ b/src/main/java/codechicken/nei/bookmark/BookmarkGrid.java @@ -452,8 +452,9 @@ public class BookmarkGrid extends ItemsGrid 0) { final GroupingItem groupingItem = ItemPanels.bookmarkPanel.groupingItem; final int sortableGroupId = ItemPanels.bookmarkPanel.sortableGroup != null - ? ItemPanels.bookmarkPanel.sortableGroup.groupId - : -3; + && ItemPanels.bookmarkPanel.sortableGroup.grid == this + ? ItemPanels.bookmarkPanel.sortableGroup.groupId + : -3; final int rowShift = this.page * this.rows; Map groups = this.gridGenerator.rowToGroupId; @@ -795,8 +796,7 @@ public class BookmarkGrid extends ItemsGrid 0) { - this.namespaces.add(new BookmarkGrid()); - } else if (this.activeNamespaceIndex == this.namespaces.size() - 2 && getActiveGrid().size() == 0) { - this.namespaces.remove(this.namespaces.size() - 1); + final int lastIndex = this.namespaces.size() - 1; + final BookmarkGrid lastGrid = this.namespaces.get(lastIndex); + final SortableGroup sortableGroup = ItemPanels.bookmarkPanel.sortableGroup; + + if (lastGrid.size() > 0) { + if (sortableGroup == null || sortableGroup.grid != lastGrid || !sortableGroup.aloneInGrid) { + this.namespaces.add(new BookmarkGrid()); + } + } else if (lastIndex > 0 && this.activeNamespaceIndex != lastIndex) { + final BookmarkGrid prevGrid = this.namespaces.get(lastIndex - 1); + + if (sortableGroup != null && sortableGroup.grid == prevGrid && sortableGroup.aloneInGrid + || prevGrid == getActiveGrid() && prevGrid.size() == 0) { + this.namespaces.remove(lastIndex); + } } return this.namespaces.size(); diff --git a/src/main/java/codechicken/nei/bookmark/SortableGroup.java b/src/main/java/codechicken/nei/bookmark/SortableGroup.java index 51764313..d206f6ac 100644 --- a/src/main/java/codechicken/nei/bookmark/SortableGroup.java +++ b/src/main/java/codechicken/nei/bookmark/SortableGroup.java @@ -13,13 +13,23 @@ public class SortableGroup { public int groupId; public BookmarkGrid grid; + public boolean aloneInGrid; public int shiftX = 0; public int shiftY = 0; public SortableGroup(BookmarkGrid grid, int groupId) { + update(grid, groupId); + } + + public void update(BookmarkGrid grid, int groupId) { this.grid = grid; this.groupId = groupId; + this.aloneInGrid = grid.bookmarkItems.stream().allMatch(item -> item.groupId == groupId); + } + + public boolean matches(BookmarkGrid grid, int groupId) { + return this.grid == grid && this.groupId == groupId; } public void postDraw(int mousex, int mousey) {