mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-15 07:50:39 +08:00
Navigate inputs on new issue form
This commit is contained in:
+18
-1
@@ -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
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user