11package dev .isxander .yacl .gui ;
22
3- import dev .isxander .yacl .api .ConfigCategory ;
4- import dev .isxander .yacl .api .OptionGroup ;
53import net .minecraft .client .font .TextRenderer ;
64import net .minecraft .client .gui .widget .TextFieldWidget ;
75import net .minecraft .client .util .math .MatrixStack ;
@@ -12,8 +10,11 @@ public class SearchFieldWidget extends TextFieldWidget {
1210 private final YACLScreen yaclScreen ;
1311 private final TextRenderer textRenderer ;
1412
13+ private boolean isEmpty = true ;
14+
1515 public SearchFieldWidget (YACLScreen yaclScreen , TextRenderer textRenderer , int x , int y , int width , int height , Text text , Text emptyText ) {
1616 super (textRenderer , x , y , width , height , text );
17+ setTextPredicate (string -> !string .endsWith (" " ) && !string .startsWith (" " ));
1718 this .yaclScreen = yaclScreen ;
1819 this .textRenderer = textRenderer ;
1920 this .emptyText = emptyText ;
@@ -22,48 +23,41 @@ public SearchFieldWidget(YACLScreen yaclScreen, TextRenderer textRenderer, int x
2223 @ Override
2324 public void renderButton (MatrixStack matrices , int mouseX , int mouseY , float delta ) {
2425 super .renderButton (matrices , mouseX , mouseY , delta );
25- if (isVisible () && getText (). isEmpty ()) {
26+ if (isVisible () && isEmpty ()) {
2627 textRenderer .drawWithShadow (matrices , emptyText , x + 4 , this .y + (this .height - 8 ) / 2f , 0x707070 );
2728 }
2829 }
2930
3031 @ Override
3132 public void write (String text ) {
32- yaclScreen .optionList .setScrollAmount (0 );
33- yaclScreen .categoryList .setScrollAmount (0 );
34- for (OptionListWidget .Entry entry : yaclScreen .optionList .children ()) {
35- if (entry instanceof OptionListWidget .GroupSeparatorEntry groupSeparatorEntry ) {
36- groupSeparatorEntry .setExpanded (true );
37- }
38- }
33+ update ();
3934
4035 super .write (text );
36+
37+ isEmpty = getText ().isEmpty ();
4138 }
4239
4340 @ Override
4441 public void eraseCharacters (int characterOffset ) {
45- yaclScreen . optionList . setScrollAmount ( 0 );
42+ update ( );
4643
4744 super .eraseCharacters (characterOffset );
48- }
4945
50- public boolean matches (OptionListWidget .OptionEntry optionEntry , boolean ignoreCategory ) {
51- return (matchesCategory (optionEntry .category ) && !ignoreCategory ) || matchesGroup (optionEntry .group ) || matchesWidget (optionEntry .widget );
46+ isEmpty = getText ().isEmpty ();
5247 }
5348
54- public boolean matchesCategory (ConfigCategory category ) {
55- return category .name ().getString ().toLowerCase ().contains (getText ().trim ());
56- }
57-
58- public boolean matchesGroup (OptionGroup group ) {
59- if (group .isRoot ())
60- return false ;
61-
62- return group .name ().getString ().toLowerCase ().contains (getText ().trim ());
49+ private void update () {
50+ yaclScreen .optionList .setScrollAmount (0 );
51+ yaclScreen .categoryList .setScrollAmount (0 );
52+ for (OptionListWidget .Entry entry : yaclScreen .optionList .children ()) {
53+ if (entry instanceof OptionListWidget .GroupSeparatorEntry groupSeparatorEntry ) {
54+ groupSeparatorEntry .setExpanded (true );
55+ }
56+ }
6357 }
6458
65- public boolean matchesWidget ( AbstractWidget widget ) {
66- return widget . matchesSearch ( getText (). trim ()) ;
59+ public boolean isEmpty ( ) {
60+ return isEmpty ;
6761 }
6862
6963 public Text getEmptyText () {
0 commit comments