diff --git a/src/ui/chat.rs b/src/ui/chat.rs index 44d2699..353ef57 100644 --- a/src/ui/chat.rs +++ b/src/ui/chat.rs @@ -53,7 +53,7 @@ impl> ChatState { } } - pub async fn handle_navigation(&mut self, event: KeyEvent) { + pub async fn handle_navigation(&mut self, event: KeyEvent) -> bool { match self.mode { Mode::Tree => self.tree.handle_navigation(event).await, } diff --git a/src/ui/chat/tree.rs b/src/ui/chat/tree.rs index f491b28..c03f34d 100644 --- a/src/ui/chat/tree.rs +++ b/src/ui/chat/tree.rs @@ -48,14 +48,15 @@ impl> InnerTreeViewState { } } - async fn handle_navigation(&mut self, event: KeyEvent) { + async fn handle_navigation(&mut self, event: KeyEvent) -> bool { match event.code { KeyCode::Up | KeyCode::Char('k') => self.move_cursor_up().await, KeyCode::Down | KeyCode::Char('j') => self.move_cursor_down().await, KeyCode::Char('g') => self.move_cursor_to_top().await, KeyCode::Char('G') => self.move_cursor_to_bottom().await, - _ => {} + _ => return false, } + true } async fn handle_messaging( @@ -86,8 +87,8 @@ impl> TreeViewState { TreeView(self.0.clone()) } - pub async fn handle_navigation(&mut self, event: KeyEvent) { - self.0.lock().await.handle_navigation(event).await; + pub async fn handle_navigation(&mut self, event: KeyEvent) -> bool { + self.0.lock().await.handle_navigation(event).await } pub async fn handle_messaging( diff --git a/src/ui/room.rs b/src/ui/room.rs index d0c6bc0..e7ae2f0 100644 --- a/src/ui/room.rs +++ b/src/ui/room.rs @@ -276,10 +276,12 @@ impl EuphRoom { terminal: &mut Terminal, crossterm_lock: &Arc>, event: KeyEvent, - ) { + ) -> bool { match &self.state { State::Normal => { - self.chat.handle_navigation(event).await; + if self.chat.handle_navigation(event).await { + return true; + } if let Some(room) = &self.room { if let Ok(Some(Status::Joined(joined))) = room.status().await { @@ -287,6 +289,7 @@ impl EuphRoom { self.state = State::ChooseNick(EditorState::with_initial_text( joined.session.name.clone(), )); + return true; } let potential_message = self @@ -295,25 +298,31 @@ impl EuphRoom { .await; if let Some((parent, content)) = potential_message { let _ = room.send(parent, content); + return true; } } } + + false } - State::ChooseNick(ed) => match event.code { - KeyCode::Esc => self.state = State::Normal, - KeyCode::Enter => { - if let Some(room) = &self.room { - let _ = room.nick(ed.text()); + State::ChooseNick(ed) => { + match event.code { + KeyCode::Esc => self.state = State::Normal, + KeyCode::Enter => { + if let Some(room) = &self.room { + let _ = room.nick(ed.text()); + } + self.state = State::Normal; } - self.state = State::Normal; + KeyCode::Backspace => ed.backspace(), + KeyCode::Left => ed.move_cursor_left(), + KeyCode::Right => ed.move_cursor_right(), + KeyCode::Delete => ed.delete(), + KeyCode::Char(ch) => ed.insert_char(ch), + _ => return false, } - KeyCode::Backspace => ed.backspace(), - KeyCode::Left => ed.move_cursor_left(), - KeyCode::Right => ed.move_cursor_right(), - KeyCode::Delete => ed.delete(), - KeyCode::Char(ch) => ed.insert_char(ch), - _ => {} - }, + true + } } } } diff --git a/src/ui/rooms.rs b/src/ui/rooms.rs index 93aefa6..6aa679e 100644 --- a/src/ui/rooms.rs +++ b/src/ui/rooms.rs @@ -237,11 +237,18 @@ impl Rooms { } _ => {} }, - State::ShowRoom(_) if event.code == KeyCode::Esc => self.state = State::ShowList, State::ShowRoom(name) => { - self.get_or_insert_room(name.clone()) + if self + .get_or_insert_room(name.clone()) .handle_key_event(terminal, crossterm_lock, event) .await + { + return; + } + + if event.code == KeyCode::Esc { + self.state = State::ShowList; + } } State::Connect(ed) => match event.code { KeyCode::Esc => self.state = State::ShowList,