Fix not being able to close nick dialog
This commit is contained in:
parent
77c5b479aa
commit
73cb568702
4 changed files with 39 additions and 22 deletions
|
|
@ -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 {
|
match self.mode {
|
||||||
Mode::Tree => self.tree.handle_navigation(event).await,
|
Mode::Tree => self.tree.handle_navigation(event).await,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
match event.code {
|
||||||
KeyCode::Up | KeyCode::Char('k') => self.move_cursor_up().await,
|
KeyCode::Up | KeyCode::Char('k') => self.move_cursor_up().await,
|
||||||
KeyCode::Down | KeyCode::Char('j') => self.move_cursor_down().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_top().await,
|
||||||
KeyCode::Char('G') => self.move_cursor_to_bottom().await,
|
KeyCode::Char('G') => self.move_cursor_to_bottom().await,
|
||||||
_ => {}
|
_ => return false,
|
||||||
}
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_messaging(
|
async fn handle_messaging(
|
||||||
|
|
@ -86,8 +87,8 @@ impl<M: Msg, S: MsgStore<M>> TreeViewState<M, S> {
|
||||||
TreeView(self.0.clone())
|
TreeView(self.0.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_navigation(&mut self, event: KeyEvent) {
|
pub async fn handle_navigation(&mut self, event: KeyEvent) -> bool {
|
||||||
self.0.lock().await.handle_navigation(event).await;
|
self.0.lock().await.handle_navigation(event).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_messaging(
|
pub async fn handle_messaging(
|
||||||
|
|
|
||||||
|
|
@ -276,10 +276,12 @@ impl EuphRoom {
|
||||||
terminal: &mut Terminal,
|
terminal: &mut Terminal,
|
||||||
crossterm_lock: &Arc<FairMutex<()>>,
|
crossterm_lock: &Arc<FairMutex<()>>,
|
||||||
event: KeyEvent,
|
event: KeyEvent,
|
||||||
) {
|
) -> bool {
|
||||||
match &self.state {
|
match &self.state {
|
||||||
State::Normal => {
|
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 Some(room) = &self.room {
|
||||||
if let Ok(Some(Status::Joined(joined))) = room.status().await {
|
if let Ok(Some(Status::Joined(joined))) = room.status().await {
|
||||||
|
|
@ -287,6 +289,7 @@ impl EuphRoom {
|
||||||
self.state = State::ChooseNick(EditorState::with_initial_text(
|
self.state = State::ChooseNick(EditorState::with_initial_text(
|
||||||
joined.session.name.clone(),
|
joined.session.name.clone(),
|
||||||
));
|
));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let potential_message = self
|
let potential_message = self
|
||||||
|
|
@ -295,25 +298,31 @@ impl EuphRoom {
|
||||||
.await;
|
.await;
|
||||||
if let Some((parent, content)) = potential_message {
|
if let Some((parent, content)) = potential_message {
|
||||||
let _ = room.send(parent, content);
|
let _ = room.send(parent, content);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
false
|
||||||
}
|
}
|
||||||
State::ChooseNick(ed) => match event.code {
|
State::ChooseNick(ed) => {
|
||||||
KeyCode::Esc => self.state = State::Normal,
|
match event.code {
|
||||||
KeyCode::Enter => {
|
KeyCode::Esc => self.state = State::Normal,
|
||||||
if let Some(room) = &self.room {
|
KeyCode::Enter => {
|
||||||
let _ = room.nick(ed.text());
|
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(),
|
true
|
||||||
KeyCode::Left => ed.move_cursor_left(),
|
}
|
||||||
KeyCode::Right => ed.move_cursor_right(),
|
|
||||||
KeyCode::Delete => ed.delete(),
|
|
||||||
KeyCode::Char(ch) => ed.insert_char(ch),
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -237,11 +237,18 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
State::ShowRoom(_) if event.code == KeyCode::Esc => self.state = State::ShowList,
|
|
||||||
State::ShowRoom(name) => {
|
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)
|
.handle_key_event(terminal, crossterm_lock, event)
|
||||||
.await
|
.await
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if event.code == KeyCode::Esc {
|
||||||
|
self.state = State::ShowList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
State::Connect(ed) => match event.code {
|
State::Connect(ed) => match event.code {
|
||||||
KeyCode::Esc => self.state = State::ShowList,
|
KeyCode::Esc => self.state = State::ShowList,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue