diff options
| author | lukeflo | 2024-12-15 13:21:42 +0100 |
|---|---|---|
| committer | lukeflo | 2024-12-23 21:03:19 +0100 |
| commit | a6fca1fcf164142d84d09242b9d95a1da0b2d2d9 (patch) | |
| tree | 08cae1f39342d5d81bb2d51554a62676899ef70e /src/app.rs | |
| parent | b892bc9a66e65cb73901d719c83768face67941d (diff) | |
| download | bibiman-a6fca1fcf164142d84d09242b9d95a1da0b2d2d9.tar.gz bibiman-a6fca1fcf164142d84d09242b9d95a1da0b2d2d9.zip | |
use input struct, place cursor at pos
Diffstat (limited to 'src/app.rs')
| -rw-r--r-- | src/app.rs | 99 |
1 files changed, 56 insertions, 43 deletions
@@ -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 => { |
