Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Properly handle up / down keys in multiline text input
Erik Kundt committed 2 years ago
commit 1ed3c5af525cf33a9b26a65a9e4399561222ae3c
parent 391d439e26b560868ec2d101134ea3b42a2221ba
2 files changed +19 -7
modified src/app/event.rs
@@ -7,7 +7,7 @@ use radicle_tui::ui::widget::common::container::{
    AppHeader, GlobalListener, LabeledContainer, Popup,
};
use radicle_tui::ui::widget::common::context::{ContextBar, Shortcuts};
-
use radicle_tui::ui::widget::common::form::TextInput;
+
use radicle_tui::ui::widget::common::form::{Form, TextInput};
use radicle_tui::ui::widget::common::list::PropertyList;
use radicle_tui::ui::widget::home::{Dashboard, IssueBrowser, PatchBrowser};
use radicle_tui::ui::widget::issue::NewForm;
@@ -132,6 +132,16 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<issue::NewForm> {
                self.perform(Cmd::Move(MoveDirection::Right));
                Some(Message::Tick)
            }
+
            Event::Keyboard(KeyEvent { code: Key::Up, .. }) => {
+
                self.perform(Cmd::Move(MoveDirection::Up));
+
                Some(Message::Tick)
+
            }
+
            Event::Keyboard(KeyEvent {
+
                code: Key::Down, ..
+
            }) => {
+
                self.perform(Cmd::Move(MoveDirection::Down));
+
                Some(Message::Tick)
+
            }
            Event::Keyboard(KeyEvent {
                code: Key::Home, ..
            }) => {
@@ -219,11 +229,11 @@ impl tuirealm::Component<Message, NoUserEvent> for Widget<issue::NewForm> {
            Event::Keyboard(KeyEvent {
                code: Key::BackTab, ..
            }) => {
-
                self.perform(Cmd::Move(MoveDirection::Up));
+
                self.perform(Cmd::Custom(Form::CMD_FOCUS_PREVIOUS));
                Some(Message::Tick)
            }
            Event::Keyboard(KeyEvent { code: Key::Tab, .. }) => {
-
                self.perform(Cmd::Move(MoveDirection::Down));
+
                self.perform(Cmd::Custom(Form::CMD_FOCUS_NEXT));
                Some(Message::Tick)
            }
            Event::Keyboard(KeyEvent {
modified src/ui/widget/common/form.rs
@@ -89,6 +89,9 @@ pub struct Form {
}

impl Form {
+
    pub const CMD_FOCUS_PREVIOUS: &str = "cmd-focus-previous";
+
    pub const CMD_FOCUS_NEXT: &str = "cmd-focus-next";
+

    pub fn new(_theme: Theme, inputs: Vec<Widget<TextInput>>) -> Self {
        let state = FormState::new(Some(0), inputs.len());

@@ -134,19 +137,18 @@ impl WidgetComponent for Form {
    }

    fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult {
-
        use tuirealm::command::Direction;
        match cmd {
-
            Cmd::Move(Direction::Up) => {
+
            Cmd::Custom(Self::CMD_FOCUS_PREVIOUS) => {
                self.state.focus_previous();
                CmdResult::None
            }
-
            Cmd::Move(Direction::Down) => {
+
            Cmd::Custom(Self::CMD_FOCUS_NEXT) => {
                self.state.focus_next();
                CmdResult::None
            }
            Cmd::Submit => {
                // Fold each input's vector of lines into a single string
-
                // that containes newlines and return a state vector with
+
                // that contains newlines and return a state vector with
                // each entry being the folded input string.
                let states = self
                    .inputs