Navigate inputs on new issue form

This commit is contained in:
Erik Kundt
2023-08-11 11:43:54 +02:00
parent a99f769635
commit a0807f5156
2 changed files with 35 additions and 3 deletions
+18 -1
View File
@@ -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<Message, NoUserEvent> for Widget<issue::NewForm> {
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,
}
}
+17 -2
View File
@@ -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,
}
}
}