diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-20 18:55:41 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-05-20 18:55:41 +0300 |
| commit | 836fd7e585af15cc1ccb0d4f04586ffec28d2a3c (patch) | |
| tree | a3bf07e7af7ffd884a38fce3d65f8c2243bc0615 /src/app/input/modal.rs | |
| parent | be66f33d2acde30d25794bcead991e5e7b7eaff8 (diff) | |
feat: add keybinding v2
refs #154
refs #201
refs #202
refs #219
Diffstat (limited to 'src/app/input/modal.rs')
| -rw-r--r-- | src/app/input/modal.rs | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/src/app/input/modal.rs b/src/app/input/modal.rs index ff5e8582..5b585221 100644 --- a/src/app/input/modal.rs +++ b/src/app/input/modal.rs @@ -2,7 +2,8 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use ratatui::layout::{Direction, Rect}; use crate::{ - app::state::{key_matches, AppState, ContextMenuKind, ContextMenuState, MenuListState, Mode}, + app::state::{AppState, ContextMenuKind, ContextMenuState, MenuListState, Mode}, + input::TerminalKey, layout::NavDirection, }; @@ -448,14 +449,12 @@ pub(crate) fn handle_rename_key(state: &mut AppState, key: KeyEvent) { } } -pub(crate) fn handle_resize_key(state: &mut AppState, key: KeyEvent) { +pub(crate) fn handle_resize_key(state: &mut AppState, raw_key: TerminalKey) { + let key = raw_key.as_key_event(); if key.code == KeyCode::Esc || key.code == KeyCode::Enter - || key_matches( - &key, - state.keybinds.resize_mode.0, - state.keybinds.resize_mode.1, - ) + || state.keybinds.resize_mode.matches_prefix_key(raw_key) + || state.keybinds.resize_mode.matches_direct_key(raw_key) { if state.active.is_some() { state.mode = Mode::Terminal; @@ -648,12 +647,43 @@ mod tests { fn custom_resize_key_exits_resize_mode() { let mut state = state_with_workspaces(&["test"]); state.mode = Mode::Resize; - state.keybinds.resize_mode = (KeyCode::Char('g'), KeyModifiers::empty()); - state.keybinds.resize_mode_label = "g".into(); + state.keybinds.resize_mode = crate::config::ActionKeybinds::prefix("g"); handle_resize_key( &mut state, - KeyEvent::new(KeyCode::Char('g'), KeyModifiers::empty()), + TerminalKey::new(KeyCode::Char('g'), KeyModifiers::empty()), + ); + + assert_eq!(state.mode, Mode::Terminal); + } + + #[test] + fn direct_resize_key_exits_resize_mode() { + let mut state = state_with_workspaces(&["test"]); + state.mode = Mode::Resize; + state.keybinds.resize_mode = crate::config::ActionKeybinds::direct("ctrl+alt+r"); + + handle_resize_key( + &mut state, + TerminalKey::new( + KeyCode::Char('r'), + KeyModifiers::CONTROL | KeyModifiers::ALT, + ), + ); + + assert_eq!(state.mode, Mode::Terminal); + } + + #[test] + fn resize_key_exit_matches_enhanced_shifted_punctuation() { + let mut state = state_with_workspaces(&["test"]); + state.mode = Mode::Resize; + state.keybinds.resize_mode = crate::config::ActionKeybinds::prefix("?"); + + handle_resize_key( + &mut state, + TerminalKey::new(KeyCode::Char('/'), KeyModifiers::SHIFT) + .with_shifted_codepoint('?' as u32), ); assert_eq!(state.mode, Mode::Terminal); |
