wip: ui: help popup while in editing mode.

This commit is contained in:
Jeremy Wall 2024-12-01 09:10:00 -05:00
parent d3d605aca9
commit e56d602376
3 changed files with 33 additions and 8 deletions

View File

@ -241,8 +241,9 @@ impl<'ws> Workspace<'ws> {
fn handle_edit_input(&mut self, key: event::KeyEvent) -> Result<Option<ExitCode>> {
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()?,
_ => {

View File

@ -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);

View File

@ -232,7 +232,10 @@ fn test_input_navitation_shift_enter_key() {
ws.handle_input(construct_key_event(KeyCode::Enter))
.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);
}
@ -246,7 +249,25 @@ fn test_input_navitation_shift_tab_key() {
ws.handle_input(construct_key_event(KeyCode::Tab))
.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);
}