@@ -69,7 +69,7 @@ def on_mount(self) -> None:
69
69
def reset_query () -> None :
70
70
self ._search_query = ""
71
71
72
- self ._search_reset_timer = Timer (self , 1.0 , callback = reset_query )
72
+ self ._search_reset_timer = Timer (self , 0.7 , callback = reset_query )
73
73
74
74
def watch_has_focus (self , value : bool ) -> None :
75
75
self ._search_query = ""
@@ -113,16 +113,27 @@ def select(self, index: int | None) -> None:
113
113
self .scroll_to_highlight ()
114
114
115
115
def _find_search_match (self , query : str ) -> int | None :
116
- """Find the first index"""
116
+ best_match : int | None = None
117
+ minimum_index : int | None = None
118
+
119
+ query = query .lower ()
117
120
for index , option in enumerate (self ._options ):
118
121
prompt = option .prompt
119
122
if isinstance (prompt , Text ):
120
- if query in prompt .plain :
121
- return index
123
+ lower_prompt = prompt .plain .lower ()
122
124
elif isinstance (prompt , str ):
123
- if query in prompt :
124
- return index
125
- return None
125
+ lower_prompt = prompt .lower ()
126
+ else :
127
+ continue
128
+
129
+ match_index = lower_prompt .find (query )
130
+ if match_index != - 1 and (
131
+ minimum_index is None or match_index < minimum_index
132
+ ):
133
+ best_match = index
134
+ minimum_index = match_index
135
+
136
+ return best_match
126
137
127
138
def action_dismiss (self ) -> None :
128
139
"""Dismiss the overlay."""
0 commit comments