Fix not being able to close nick dialog

This commit is contained in:
Joscha 2022-07-23 23:45:01 +02:00
parent 77c5b479aa
commit 73cb568702
4 changed files with 39 additions and 22 deletions

View file

@ -53,7 +53,7 @@ impl<M: Msg, S: MsgStore<M>> ChatState<M, S> {
}
}
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,
}

View file

@ -48,14 +48,15 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
}
}
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<M: Msg, S: MsgStore<M>> TreeViewState<M, S> {
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(

View file

@ -276,10 +276,12 @@ impl EuphRoom {
terminal: &mut Terminal,
crossterm_lock: &Arc<FairMutex<()>>,
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
}
}
}
}

View file

@ -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,