@@ -132,7 +132,7 @@ var global_settings: ?Settings = null;
132132var settings_mutex = std.Thread.Mutex {};
133133
134134/// Update global settings
135- pub fn updateSettings (allocator : std.mem.Allocator , new_settings : Settings ) ! void {
135+ pub fn updateSettings (_ : std.mem.Allocator , new_settings : Settings ) ! void {
136136 settings_mutex .lock ();
137137 defer settings_mutex .unlock ();
138138
@@ -200,4 +200,90 @@ test "settings" {
200200 settings .use_vim_keys = true ;
201201 try std .testing .expect (settings .isActionKey ("k" , .up ));
202202 try std .testing .expect (settings .isActionKey ("j" , .down ));
203+ try std .testing .expect (settings .isActionKey ("h" , .left ));
204+ try std .testing .expect (settings .isActionKey ("l" , .right ));
205+ try std .testing .expect (settings .isActionKey ("q" , .cancel ));
206+ }
207+
208+ test "action from key - edge cases" {
209+ // Test all arrow keys
210+ try std .testing .expect (Action .fromKey ("\x1B [A" ) == .up );
211+ try std .testing .expect (Action .fromKey ("\x1B [B" ) == .down );
212+ try std .testing .expect (Action .fromKey ("\x1B [C" ) == .right );
213+ try std .testing .expect (Action .fromKey ("\x1B [D" ) == .left );
214+
215+ // Test home and end
216+ try std .testing .expect (Action .fromKey ("\x1B [H" ) == .home );
217+ try std .testing .expect (Action .fromKey ("\x1B [F" ) == .end );
218+
219+ // Test delete
220+ try std .testing .expect (Action .fromKey ("\x1B [3~" ) == .delete );
221+
222+ // Test single character keys
223+ try std .testing .expect (Action .fromKey (" " ) == .space );
224+ try std .testing .expect (Action .fromKey ("\n " ) == .enter );
225+ try std .testing .expect (Action .fromKey ("\r " ) == .enter );
226+ try std .testing .expect (Action .fromKey ("\t " ) == .tab );
227+ try std .testing .expect (Action .fromKey ("\x1B " ) == .cancel );
228+ try std .testing .expect (Action .fromKey ("\x7F " ) == .backspace );
229+ try std .testing .expect (Action .fromKey ("\x08 " ) == .backspace );
230+
231+ // Test invalid keys
232+ try std .testing .expect (Action .fromKey ("" ) == null );
233+ try std .testing .expect (Action .fromKey ("a" ) == null );
234+ try std .testing .expect (Action .fromKey ("\x1B [Z" ) == null );
235+ try std .testing .expect (Action .fromKey ("\x1B [" ) == null );
236+ }
237+
238+ test "state transitions" {
239+ var current = State .initial ;
240+ try std .testing .expect (! current .isActive ());
241+ try std .testing .expect (! current .isFinished ());
242+
243+ current = State .active ;
244+ try std .testing .expect (current .isActive ());
245+ try std .testing .expect (! current .isFinished ());
246+
247+ current = State .submit ;
248+ try std .testing .expect (! current .isActive ());
249+ try std .testing .expect (current .isFinished ());
250+
251+ current = State .cancel ;
252+ try std .testing .expect (! current .isActive ());
253+ try std .testing .expect (current .isFinished ());
254+
255+ current = State .@"error" ;
256+ try std .testing .expect (! current .isActive ());
257+ try std .testing .expect (current .isFinished ());
258+ }
259+
260+ test "settings - custom mappings override standard" {
261+ const allocator = std .testing .allocator ;
262+
263+ var settings = Settings .init (allocator );
264+ defer settings .deinit ();
265+
266+ // Map 'k' to cancel (overriding vim up)
267+ try settings .mapKey ("k" , .cancel );
268+ settings .use_vim_keys = true ;
269+
270+ // Custom mapping should take precedence
271+ try std .testing .expect (settings .isActionKey ("k" , .cancel ));
272+ try std .testing .expect (! settings .isActionKey ("k" , .up ));
273+ }
274+
275+ test "settings - multiple custom mappings" {
276+ const allocator = std .testing .allocator ;
277+
278+ var settings = Settings .init (allocator );
279+ defer settings .deinit ();
280+
281+ try settings .mapKey ("a" , .up );
282+ try settings .mapKey ("b" , .down );
283+ try settings .mapKey ("c" , .cancel );
284+
285+ try std .testing .expect (settings .isActionKey ("a" , .up ));
286+ try std .testing .expect (settings .isActionKey ("b" , .down ));
287+ try std .testing .expect (settings .isActionKey ("c" , .cancel ));
288+ try std .testing .expect (! settings .isActionKey ("d" , .up ));
203289}
0 commit comments