Skip to content

Commit c5b05c8

Browse files
committed
Fix quick search close on ESC
1 parent ab62d15 commit c5b05c8

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.mixin.render;
19+
20+
import com.lambda.gui.components.QuickSearch;
21+
import net.minecraft.client.gui.screen.Screen;
22+
import org.lwjgl.glfw.GLFW;
23+
import org.spongepowered.asm.mixin.Mixin;
24+
import org.spongepowered.asm.mixin.injection.At;
25+
import org.spongepowered.asm.mixin.injection.Inject;
26+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
27+
28+
@Mixin(Screen.class)
29+
public class ScreenMixin {
30+
31+
@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
32+
private void onKeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
33+
if (keyCode == GLFW.GLFW_KEY_ESCAPE && QuickSearch.INSTANCE.isOpen()) {
34+
QuickSearch.INSTANCE.close();
35+
cir.setReturnValue(true);
36+
}
37+
}
38+
}

src/main/kotlin/com/lambda/gui/components/QuickSearch.kt

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import kotlin.math.max
4343
// ToDo: Add support for searching of menu bar entries
4444
object QuickSearch {
4545
private val searchInput = ImString(256)
46-
private var isOpen = false
46+
var isOpen = false
47+
private set
4748
private var shouldFocus = false
4849

4950
private var lastShiftPressTime = 0L
@@ -128,21 +129,6 @@ object QuickSearch {
128129
ImGui.setNextWindowSizeConstraints(0f, 0f, maxW, maxH)
129130

130131
popupModal("QuickSearch", WINDOW_FLAGS) {
131-
// ToDo: Fix close with background click and escape
132-
if (ImGui.isKeyPressed(256)) { // ESC key
133-
close()
134-
ImGui.closeCurrentPopup()
135-
return@popupModal
136-
}
137-
138-
// val bgClick = (ImGui.isMouseClicked(0) || ImGui.isMouseClicked(1)) &&
139-
// !ImGui.isWindowHovered(ImGuiHoveredFlags.AnyWindow)
140-
// if (bgClick) {
141-
// close()
142-
// ImGui.closeCurrentPopup()
143-
// return@popupModal
144-
// }
145-
146132
if (shouldFocus) {
147133
ImGui.setKeyboardFocusHere()
148134
shouldFocus = false

src/main/resources/lambda.mixins.common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"render.PlayerListHudMixin",
4848
"render.RenderLayersMixin",
4949
"render.ScreenHandlerMixin",
50+
"render.ScreenMixin",
5051
"render.SplashOverlayMixin",
5152
"render.SplashOverlayMixin$LogoTextureMixin",
5253
"render.TooltipComponentMixin",

0 commit comments

Comments
 (0)