Skip to content

Commit

Permalink
fix: grid search bar not losing focus properly
Browse files Browse the repository at this point in the history
Fixes #3579
Fixes #2913
  • Loading branch information
raoulvdberge committed Nov 5, 2023
1 parent 9b30bec commit 0f325ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,15 @@ private void drawGridTooltip(GuiGraphics graphics, IGridStack gridStack, int mou
@Override
public boolean mouseClicked(double mouseX, double mouseY, int clickedButton) {
if (tabs.mouseClicked()) {
setFocused(null);
return true;
}

if (scrollbar.mouseClicked(mouseX, mouseY, clickedButton)) {
setFocused(null);
return true;
}
if (grid.getGridType() == GridType.PATTERN && patternScrollbar.mouseClicked(mouseX, mouseY, clickedButton)) {
setFocused(null);
return true;
}
if (RS.CLIENT_CONFIG.getGrid().getPreventSortingWhileShiftIsDown()) {
Expand All @@ -551,12 +553,16 @@ public boolean mouseClicked(double mouseX, double mouseY, int clickedButton) {

RS.NETWORK_HANDLER.sendToServer(new GridPatternCreateMessage(((GridNetworkNode) grid).getPos()));

setFocused(null);

return true;
} else if (clickedClear) {
minecraft.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));

RS.NETWORK_HANDLER.sendToServer(new GridClearMessage());

setFocused(null);

return true;
} else if (grid.isGridActive()) {
ItemStack held = menu.getCarried();
Expand All @@ -567,6 +573,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int clickedButton) {
} else {
RS.NETWORK_HANDLER.sendToServer(new GridItemInsertHeldMessage(clickedButton == 1));
}
setFocused(null);

return true;
}
Expand Down Expand Up @@ -596,6 +603,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int clickedButton) {
}
}

setFocused(null);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,22 @@ private boolean canSyncFromJEINow() {

@Override
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
boolean wasFocused = isFocused();

boolean result = super.mouseClicked(mouseX, mouseY, mouseButton);

boolean clickedWidget = mouseX >= this.getX() && mouseX < this.getX() + this.width && mouseY >= this.getY() && mouseY < this.getY() + this.height;

if (clickedWidget && mouseButton == 1) {
// On right click, clear the widget and focus, save history if necessary.
if (isFocused()) {
saveHistory();
}
setValue("");
setFocused(true);
} else if (wasFocused != isFocused()) {
}

if (!clickedWidget && isFocused()) {
// If we are focused, and we click outside the search box, lose focus.
saveHistory();
setFocused(false);
}

return result;
Expand Down

1 comment on commit 0f325ef

@comploplo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Raoul!

Please sign in to comment.