mirror of
https://github.com/zaphar/sheetsui.git
synced 2025-07-22 13:00:22 -04:00
wip: ui: help popup while in editing mode.
This commit is contained in:
parent
d3d605aca9
commit
e56d602376
@ -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()?,
|
||||
_ => {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user