From a0807f51564163c4701fc97b03f85b2172fff53b Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Tue, 4 Jul 2023 14:10:20 +0200 Subject: [PATCH] Navigate inputs on new issue form --- src/app/event.rs | 19 ++++++++++++++++++- src/ui/widget/issue.rs | 19 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/app/event.rs b/src/app/event.rs index 6616ee95..7bba457e 100644 --- a/src/app/event.rs +++ b/src/app/event.rs @@ -1,5 +1,5 @@ use tuirealm::command::{Cmd, CmdResult, Direction as MoveDirection}; -use tuirealm::event::{Event, Key, KeyEvent}; +use tuirealm::event::{Event, Key, KeyEvent, KeyModifiers}; use tuirealm::{MockComponent, NoUserEvent, State, StateValue}; use radicle_tui::ui::widget::common::container::{ @@ -115,6 +115,23 @@ impl tuirealm::Component for Widget { Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => { Some(Message::Issue(IssueMessage::ClosePopup(IssueCid::NewForm))) } + Event::Keyboard(KeyEvent { + code: Key::BackTab, .. + }) => { + self.perform(Cmd::Move(MoveDirection::Up)); + Some(Message::Tick) + } + Event::Keyboard(KeyEvent { code: Key::Tab, .. }) => { + self.perform(Cmd::Move(MoveDirection::Down)); + Some(Message::Tick) + } + Event::Keyboard(KeyEvent { + code: Key::Char('s'), + modifiers: KeyModifiers::ALT, + }) => { + self.perform(Cmd::Submit); + None + } _ => None, } } diff --git a/src/ui/widget/issue.rs b/src/ui/widget/issue.rs index 80053302..9cb05814 100644 --- a/src/ui/widget/issue.rs +++ b/src/ui/widget/issue.rs @@ -300,7 +300,11 @@ impl NewForm { impl WidgetComponent for NewForm { fn view(&mut self, _properties: &Props, frame: &mut Frame, area: Rect) { + // Clear and set current focus let focus = self.state.focus().unwrap_or(0); + for input in &mut self.inputs { + input.attr(Attribute::Focus, AttrValue::Flag(false)); + } if let Some(input) = self.inputs.get_mut(focus) { input.attr(Attribute::Focus, AttrValue::Flag(true)); } @@ -326,8 +330,19 @@ impl WidgetComponent for NewForm { State::None } - fn perform(&mut self, _properties: &Props, _cmd: Cmd) -> CmdResult { - CmdResult::None + fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult { + use tuirealm::command::Direction; + match cmd { + Cmd::Move(Direction::Up) => { + self.state.focus_previous(); + CmdResult::None + } + Cmd::Move(Direction::Down) => { + self.state.focus_next(); + CmdResult::None + } + _ => CmdResult::None, + } } }