diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 234ef0a..afb7ffb 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -241,8 +241,9 @@ impl<'ws> Workspace<'ws> { fn handle_edit_input(&mut self, key: event::KeyEvent) -> Result> { if key.kind == KeyEventKind::Press { match key.code { - KeyCode::Char('?') => { + KeyCode::Char('?') if key.modifiers == KeyModifiers::CONTROL => { self.enter_dialog_mode(self.render_help_text()); + return Ok(None); } KeyCode::Esc | KeyCode::Enter => self.exit_edit_mode()?, _ => { diff --git a/src/ui/render/mod.rs b/src/ui/render/mod.rs index a1d282f..8f071a6 100644 --- a/src/ui/render/mod.rs +++ b/src/ui/render/mod.rs @@ -32,7 +32,10 @@ impl<'ws> Workspace<'ws> { .select(Some(ws.book.current_sheet as usize)); tabs.render(rect, buf); }), - Box::new(|rect: Rect, buf: &mut Buffer, ws: &mut Self| ws.text_area.render(rect, buf)), + Box::new(|rect: Rect, buf: &mut Buffer, ws: &mut Self| { + // TODO(zaphar): Show a small help text? + ws.text_area.render(rect, buf) + }), Box::new(move |rect: Rect, buf: &mut Buffer, ws: &mut Self| { let sheet_name = ws.book.get_sheet_name().unwrap_or("Unknown"); let table_block = Block::bordered().title_top(sheet_name); diff --git a/src/ui/test.rs b/src/ui/test.rs index d8761f4..d4c80b0 100644 --- a/src/ui/test.rs +++ b/src/ui/test.rs @@ -208,7 +208,7 @@ fn test_input_navitation_enter_key() { let row = ws.book.location.row; assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); ws.handle_input(construct_key_event(KeyCode::Enter)) - .expect("Failed to handle enter key"); + .expect("Failed to handle enter key"); assert_eq!(row + 1, ws.book.location.row); } @@ -219,7 +219,7 @@ fn test_input_navitation_tab_key() { let col = dbg!(ws.book.location.col); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); ws.handle_input(construct_key_event(KeyCode::Tab)) - .expect("Failed to handle enter key"); + .expect("Failed to handle enter key"); assert_eq!(col + 1, ws.book.location.col); } @@ -230,9 +230,12 @@ fn test_input_navitation_shift_enter_key() { let row = ws.book.location.row; assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); ws.handle_input(construct_key_event(KeyCode::Enter)) - .expect("Failed to handle enter key"); + .expect("Failed to handle enter key"); assert_eq!(row + 1, ws.book.location.row); - ws.handle_input(construct_modified_key_event(KeyCode::Enter, KeyModifiers::SHIFT)) + ws.handle_input(construct_modified_key_event( + KeyCode::Enter, + KeyModifiers::SHIFT, + )) .expect("Failed to handle enter key"); assert_eq!(row, ws.book.location.row); } @@ -244,9 +247,27 @@ fn test_input_navitation_shift_tab_key() { let col = dbg!(ws.book.location.col); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); ws.handle_input(construct_key_event(KeyCode::Tab)) - .expect("Failed to handle enter key"); + .expect("Failed to handle enter key"); assert_eq!(col + 1, ws.book.location.col); - ws.handle_input(construct_modified_key_event(KeyCode::Tab, KeyModifiers::SHIFT)) + ws.handle_input(construct_modified_key_event( + KeyCode::Tab, + KeyModifiers::SHIFT, + )) .expect("Failed to handle enter key"); assert_eq!(col, ws.book.location.col); } + +#[test] +fn test_edit_mode_help_keycode() { + let mut ws = + Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook"); + assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); + ws.handle_input(construct_key_event(KeyCode::Char('i'))) + .expect("Failed to handle 'i' key"); + assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last()); + let edit_help = ws.render_help_text(); + ws.handle_input(construct_modified_key_event(KeyCode::Char('?'), KeyModifiers::CONTROL)) + .expect("Failed to handle 'ctrl-?' key event"); + assert_eq!(Some(&Modality::Dialog), ws.state.modality_stack.last()); + assert_eq!(edit_help, ws.state.popup); +}