Skip to content

Commit

Permalink
feat(ui): map ctrl + n/p to move cursor up/down
Browse files Browse the repository at this point in the history
  • Loading branch information
ShoheiKamiya committed Jan 25, 2025
1 parent 27b99ca commit a99fa0b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/usecase/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
};
use anyhow::{anyhow, bail, Result};
use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture, KeyCode, KeyEvent},
event::{DisableMouseCapture, EnableMouseCapture, KeyCode, KeyModifiers, KeyEvent},
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
Expand Down Expand Up @@ -72,7 +72,15 @@ impl Model<'_> {
_ => match s.current_pane {
CurrentPane::Main => match key.code {
KeyCode::Down => Some(Message::NextCommand),
KeyCode::Char('n') => match key.modifiers {
KeyModifiers::CONTROL => Some(Message::NextCommand),
_ => None,
}
KeyCode::Up => Some(Message::PreviousCommand),
KeyCode::Char('p') => match key.modifiers {
KeyModifiers::CONTROL => Some(Message::PreviousCommand),
_ => None,
}
KeyCode::Enter => Some(Message::ExecuteCommand),
_ => Some(Message::SearchTextAreaKeyInput(key)),
},
Expand Down Expand Up @@ -945,7 +953,7 @@ mod test {
},
},
Case {
title: "PreviousCommand when there is no commands to select,
title: "PreviousCommand when there is no commands to select,
panic should not occur",
model: {
let mut m = Model {
Expand Down Expand Up @@ -1011,7 +1019,7 @@ mod test {
},
},
Case {
title: "When the last history is selected and NextHistory is received,
title: "When the last history is selected and NextHistory is received,
it returns to the beginning.",
model: Model {
app_state: AppState::SelectCommand(SelectCommandState {
Expand All @@ -1030,7 +1038,7 @@ mod test {
},
},
Case {
title: "When the first history is selected and PreviousHistory is received,
title: "When the first history is selected and PreviousHistory is received,
it moves to the last history.",
model: Model {
app_state: AppState::SelectCommand(SelectCommandState {
Expand Down

0 comments on commit a99fa0b

Please sign in to comment.