Skip to content

Commit 95c8716

Browse files
committed
Make cntrl + f focus the search window when in the gui
1 parent 3a826ba commit 95c8716

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

src/main/java/meteordevelopment/meteorclient/gui/screens/ModulesScreen.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import meteordevelopment.meteorclient.systems.modules.Module;
2020
import meteordevelopment.meteorclient.systems.modules.Modules;
2121
import meteordevelopment.meteorclient.utils.misc.NbtUtils;
22+
import net.minecraft.client.input.KeyInput;
23+
import net.minecraft.client.util.MacWindowUtil;
2224
import net.minecraft.item.Items;
2325
import net.minecraft.util.Pair;
2426

@@ -28,9 +30,12 @@
2830

2931
import static meteordevelopment.meteorclient.utils.Utils.getWindowHeight;
3032
import static meteordevelopment.meteorclient.utils.Utils.getWindowWidth;
33+
import static org.lwjgl.glfw.GLFW.*;
3134

3235
public class ModulesScreen extends TabScreen {
3336
private WCategoryController controller;
37+
private WWindow searchWindow;
38+
private WTextBox searchTextBox;
3439

3540
public ModulesScreen(GuiTheme theme) {
3641
super(theme, Tabs.get().getFirst());
@@ -115,6 +120,7 @@ protected void createSearchW(WContainer w, String text) {
115120
protected WWindow createSearch(WContainer c) {
116121
WWindow w = theme.window("Search");
117122
w.id = "search";
123+
searchWindow = w;
118124

119125
if (theme.categoryIcons()) {
120126
w.beforeHeaderInit = wContainer -> wContainer.add(theme.item(Items.COMPASS.getDefaultStack())).pad(2);
@@ -129,6 +135,7 @@ protected WWindow createSearch(WContainer c) {
129135

130136
WTextBox text = w.add(theme.textBox("")).minWidth(140).expandX().widget();
131137
text.setFocused(true);
138+
searchTextBox = text;
132139
text.action = () -> {
133140
l.clear();
134141
createSearchW(l, text.get());
@@ -140,6 +147,25 @@ protected WWindow createSearch(WContainer c) {
140147
return w;
141148
}
142149

150+
@Override
151+
public boolean keyPressed(KeyInput value) {
152+
if (locked) return false;
153+
154+
boolean cntrl = MacWindowUtil.IS_MAC ? value.modifiers() == GLFW_MOD_SUPER : value.modifiers() == GLFW_MOD_CONTROL;
155+
156+
if (cntrl && value.key() == GLFW_KEY_F) {
157+
if (searchWindow != null) searchWindow.setExpanded(true);
158+
if (searchTextBox != null) {
159+
searchTextBox.setFocused(true);
160+
searchTextBox.setCursorMax();
161+
}
162+
163+
return true;
164+
}
165+
166+
return super.keyPressed(value);
167+
}
168+
143169
// Favorites
144170

145171
protected Cell<WWindow> createFavorites(WContainer c) {
@@ -193,7 +219,8 @@ public boolean fromClipboard() {
193219
}
194220

195221
@Override
196-
public void reload() {}
222+
public void reload() {
223+
}
197224

198225
// Stuff
199226

@@ -227,8 +254,7 @@ protected void refresh() {
227254
if (favorites == null) {
228255
favorites = createFavorites(this);
229256
if (favorites != null) windows.add(favorites.widget());
230-
}
231-
else {
257+
} else {
232258
favorites.widget().clear();
233259

234260
if (!createFavoritesW(favorites.widget())) {

0 commit comments

Comments
 (0)