From a6fca1fcf164142d84d09242b9d95a1da0b2d2d9 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Sun, 15 Dec 2024 13:21:42 +0100 Subject: use input struct, place cursor at pos --- src/app.rs | 99 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 43 deletions(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index 2834e61..bcdef39 100644 --- a/src/app.rs +++ b/src/app.rs @@ -79,47 +79,49 @@ impl App { } else if let Some(PopupKind::MessageError) = self.bibiman.popup_area.popup_kind { self.bibiman.close_popup() - } else if let Some(PopupKind::AddEntry) = self.bibiman.popup_area.popup_kind { - // Handle key events for AddEntry popup - match key_event.code { - KeyCode::Char(c) => { - let index = self.bibiman.popup_area.add_entry_cursor_position; - self.bibiman.popup_area.add_entry_input.insert(index, c); - self.bibiman.popup_area.add_entry_cursor_position += 1; - } - KeyCode::Backspace => { - if self.bibiman.popup_area.add_entry_cursor_position > 0 { - self.bibiman.popup_area.add_entry_cursor_position -= 1; - let index = self.bibiman.popup_area.add_entry_cursor_position; - self.bibiman.popup_area.add_entry_input.remove(index); - } - } - KeyCode::Left => { - if self.bibiman.popup_area.add_entry_cursor_position > 0 { - self.bibiman.popup_area.add_entry_cursor_position -= 1; - } - } - KeyCode::Right => { - if self.bibiman.popup_area.add_entry_cursor_position - < self.bibiman.popup_area.add_entry_input.len() - { - self.bibiman.popup_area.add_entry_cursor_position += 1; - } - } - KeyCode::Enter => { - // Handle submission of the new entry - self.bibiman.handle_new_entry_submission(args); - self.bibiman.close_popup(); - self.input_mode = false; - } - KeyCode::Esc => { - // Close the popup without saving - self.bibiman.close_popup(); - self.input_mode = false; - } - _ => {} - } - } else { + } + // else if let Some(PopupKind::AddEntry) = self.bibiman.popup_area.popup_kind { + // // Handle key events for AddEntry popup + // match key_event.code { + // KeyCode::Char(c) => { + // let index = self.bibiman.popup_area.add_entry_cursor_position; + // self.bibiman.popup_area.add_entry_input.insert(index, c); + // self.bibiman.popup_area.add_entry_cursor_position += 1; + // } + // KeyCode::Backspace => { + // if self.bibiman.popup_area.add_entry_cursor_position > 0 { + // self.bibiman.popup_area.add_entry_cursor_position -= 1; + // let index = self.bibiman.popup_area.add_entry_cursor_position; + // self.bibiman.popup_area.add_entry_input.remove(index); + // } + // } + // KeyCode::Left => { + // if self.bibiman.popup_area.add_entry_cursor_position > 0 { + // self.bibiman.popup_area.add_entry_cursor_position -= 1; + // } + // } + // KeyCode::Right => { + // if self.bibiman.popup_area.add_entry_cursor_position + // < self.bibiman.popup_area.add_entry_input.len() + // { + // self.bibiman.popup_area.add_entry_cursor_position += 1; + // } + // } + // KeyCode::Enter => { + // // Handle submission of the new entry + // self.bibiman.handle_new_entry_submission(args, &self.input); + // self.bibiman.close_popup(); + // self.input_mode = false; + // } + // KeyCode::Esc => { + // // Close the popup without saving + // self.bibiman.close_popup(); + // self.input_mode = false; + // } + // _ => {} + // } + // } + else { let command = if self.input_mode { CmdAction::Input(InputCmdAction::parse(key_event, &self.input)) } else { @@ -183,18 +185,28 @@ impl App { // self.bibiman.enter_search_area(); } InputCmdAction::Confirm => { - self.input = Input::default(); - self.input_mode = false; // Logic for TABS to be added if let CurrentArea::SearchArea = self.bibiman.current_area { self.bibiman.confirm_search(); + } else if let CurrentArea::PopupArea = self.bibiman.current_area { + match self.bibiman.popup_area.popup_kind { + Some(PopupKind::AddEntry) => { + self.bibiman.handle_new_entry_submission(args, &self.input); + self.bibiman.close_popup(); + } + _ => {} + } } + self.input = Input::default(); + self.input_mode = false; } InputCmdAction::Exit => { self.input = Input::default(); self.input_mode = false; if let CurrentArea::SearchArea = self.bibiman.current_area { self.bibiman.break_search(); + } else if let CurrentArea::PopupArea = self.bibiman.current_area { + self.bibiman.close_popup(); } } }, @@ -380,6 +392,7 @@ impl App { } } CmdAction::AddEntry => { + self.input_mode = true; self.bibiman.add_entry(); } CmdAction::ShowHelp => { -- cgit v1.2.3