Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Navigate inputs on new issue form
Erik Kundt committed 2 years ago
commit a0807f51564163c4701fc97b03f85b2172fff53b
parent a99f769635cae0b280f02a76dee4d5763e3edbf7
2 files changed +35 -3
modified 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<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,
        }
    }
modified 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,
+
        }
    }
}