@@ -99,6 +99,7 @@ def __init__(self):
99
99
self .input_string = ""
100
100
self .all_entries = get_entries_from_file ()
101
101
self .matches = []
102
+ self .start = 0
102
103
self .selected_option_index = 0
103
104
104
105
self .screen = curses .initscr ()
@@ -143,7 +144,10 @@ def _get_vertical_real_estate(self):
143
144
144
145
145
146
def _match (self , entry , query ):
146
- query_words = query .split ()
147
+
148
+ # TODO later: smartcase
149
+ entry = list (map (str .lower , entry ))
150
+ query_words = query .lower ().split ()
147
151
148
152
for word in query_words :
149
153
if word not in entry [0 ] and word not in entry [1 ]:
@@ -161,7 +165,7 @@ def _search_suggestions(self, query_string):
161
165
162
166
screen_vertical_real_estate = self ._get_vertical_real_estate ()
163
167
164
- for idx , match in enumerate (self .matches [: screen_vertical_real_estate ]):
168
+ for idx , match in enumerate (self .matches [self . start : self . start + screen_vertical_real_estate ]):
165
169
try :
166
170
line_number = idx * 2 + 1
167
171
if self .selected_option_index != idx :
@@ -204,12 +208,21 @@ def _handle_keypress(self, pressed_key):
204
208
205
209
elif pressed_key == curses .KEY_DOWN :
206
210
screen_vertical_real_estate = self ._get_vertical_real_estate ()
207
- if self .selected_option_index < screen_vertical_real_estate - 1 :
211
+
212
+ if self .start + self .selected_option_index + 1 >= len (self .matches ): # already at the bottom
213
+ return
214
+ if self .selected_option_index < screen_vertical_real_estate - 1 : # visible page remains same but highlight the next
208
215
self .selected_option_index += 1
216
+
217
+ else : # move the visible page down by 1 to highlight the next
218
+ self .start += 1
209
219
210
220
elif pressed_key == curses .KEY_UP :
211
221
if self .selected_option_index > 0 :
212
222
self .selected_option_index -= 1
223
+ else :
224
+ self .start -= min (self .start , 1 )
225
+ # todo later: scroll wrap
213
226
214
227
elif pressed_key == 27 : # Exit on escape
215
228
raise
0 commit comments