Skip to content

Commit 53b1c12

Browse files
committed
fix focus behavior on search bar
1 parent 9ca3924 commit 53b1c12

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/VideoSettingsScreen.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.util.List;
3737
import java.util.stream.Stream;
3838

39-
// TODO: make the search bar work
4039
// TODO: wrap options within groups in two columns
4140
// TODO: make the mod config headers interactive: only show one mod's pages at a time, click on a mod header to open that mod's first settings page and close the previous mod's page list
4241
// TODO: change the scroll bar colors to make it look better against a lighter gray background
@@ -266,8 +265,7 @@ private void undoChanges() {
266265
}
267266

268267
private void openDonationPage() {
269-
Util.getPlatform()
270-
.openUri("https://caffeinemc.net/donate");
268+
Util.getPlatform().openUri("https://caffeinemc.net/donate");
271269
}
272270

273271
@Override
@@ -302,7 +300,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
302300
return true;
303301
}
304302

305-
// TODO: switching between the search and the regular mode breaks the keyboard focus
303+
// this ensures the right element is focused when the search bar is clicked
306304
if (this.getFocused() == this.pageList && this.controlList == this.searchWidget ||
307305
this.getFocused() == this.searchWidget && this.controlList == this.optionList) {
308306
this.setFocused(this.controlList);
@@ -402,13 +400,23 @@ private void startSearch(@Nullable SearchWidget old) {
402400
this.searchWidget = new SearchWidget(this, this::closeSearch, old, new Dim2i(0, 0, Layout.PAGE_LIST_WIDTH + Layout.INNER_MARGIN + Layout.OPTION_WIDTH, this.height));
403401
this.addRenderableWidget(this.searchWidget);
404402

403+
// remove focus from page list even if it doesn't get destroyed so that it isn't focused when the search is closed
404+
this.pageList.setFocused(null);
405+
405406
this.removeWidget(this.pageList);
406407
this.removeWidget(this.optionList);
407408

409+
// set the search widget to be the focused element in search mode
408410
this.controlList = this.searchWidget;
411+
this.setFocused(this.searchWidget);
409412
}
410413

411414
private void closeSearch() {
415+
// remove focus from the search widget that's getting removed
416+
if (this.getFocused() == this.searchWidget) {
417+
this.clearFocus();
418+
}
419+
412420
this.removeWidget(this.searchWidget);
413421
this.searchWidget = null;
414422

common/src/main/java/net/caffeinemc/mods/sodium/client/gui/widgets/SearchWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private void triggerSearch(String text) {
256256
return;
257257
}
258258

259-
this.query = text;
259+
this.query = text.stripLeading();
260260
this.search();
261261
}
262262

0 commit comments

Comments
 (0)