| 33 | } |
| 34 | |
| 35 | pub fn handle_list_mode(state: &mut AppState, key: KeyEvent) { |
| 36 | match key.code { |
| 37 | KeyCode::Char('q') if key.modifiers.contains(KeyModifiers::CONTROL) => { |
| 38 | state.should_quit = true; |
| 39 | } |
| 40 | KeyCode::Char('a') => { |
| 41 | state.mode = Mode::Add; |
| 42 | state.input_key.clear(); |
| 43 | state.input_value.clear(); |
| 44 | state.input_cursor_key = 0; |
| 45 | state.input_cursor_value = 0; |
| 46 | state.input_focus = InputFocus::Key; |
| 47 | } |
| 48 | KeyCode::Char('e') => { |
| 49 | if let Some((k, v)) = state.entries.get(state.current_index) { |
| 50 | state.mode = Mode::Edit(k.clone()); |
| 51 | state.input_value = v.clone(); |
| 52 | state.input_cursor_value = state.input_value.len(); |
| 53 | } |
| 54 | } |
| 55 | KeyCode::Char('d') => { |
| 56 | if let Some((k, _)) = state.entries.get(state.current_index) { |
| 57 | state.mode = Mode::Delete(k.clone()); |
| 58 | } |
| 59 | } |
| 60 | KeyCode::Down => { |
| 61 | if state.current_index < state.entries.len().saturating_sub(1) { |
| 62 | state.current_index += 1; |
| 63 | let visible = 10; |
| 64 | if state.current_index >= state.scroll_offset + visible { |
| 65 | state.scroll_offset += 1; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | KeyCode::Up => { |
| 70 | if state.current_index > 0 { |
| 71 | state.current_index -= 1; |
| 72 | if state.current_index < state.scroll_offset { |
| 73 | state.scroll_offset = state.current_index; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | KeyCode::Char('r') if key.modifiers.contains(KeyModifiers::CONTROL) => { |
| 78 | state.request_reload(); |
| 79 | } |
| 80 | _ => {} |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | pub fn handle_add_mode(state: &mut AppState, key: KeyEvent) { |
| 85 | match key.code { |