Overhaul UI event handling
This commit is contained in:
parent
ade06efa01
commit
ded927b9f0
9 changed files with 177 additions and 103 deletions
|
|
@ -79,7 +79,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
bindings.binding("z", "center cursor on screen");
|
||||
}
|
||||
|
||||
async fn handle_movement_event(&mut self, frame: &mut Frame, event: &InputEvent) -> bool {
|
||||
async fn handle_movement_input_event(&mut self, frame: &mut Frame, event: &InputEvent) -> bool {
|
||||
let chat_height = frame.size().height - 3;
|
||||
|
||||
match event {
|
||||
|
|
@ -115,7 +115,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
bindings.binding("ctrl+s", "mark all older messages as seen");
|
||||
}
|
||||
|
||||
async fn handle_action_event(&mut self, event: &InputEvent, id: Option<&M::Id>) -> bool {
|
||||
async fn handle_action_input_event(&mut self, event: &InputEvent, id: Option<&M::Id>) -> bool {
|
||||
match event {
|
||||
key!(' ') => {
|
||||
if let Some(id) = id {
|
||||
|
|
@ -162,7 +162,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
bindings.binding("t", "start a new thread");
|
||||
}
|
||||
|
||||
async fn handle_edit_initiating_event(
|
||||
async fn handle_edit_initiating_input_event(
|
||||
&mut self,
|
||||
event: &InputEvent,
|
||||
id: Option<M::Id>,
|
||||
|
|
@ -198,7 +198,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
}
|
||||
}
|
||||
|
||||
async fn handle_normal_event(
|
||||
async fn handle_normal_input_event(
|
||||
&mut self,
|
||||
frame: &mut Frame,
|
||||
event: &InputEvent,
|
||||
|
|
@ -206,12 +206,12 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
id: Option<M::Id>,
|
||||
) -> bool {
|
||||
#[allow(clippy::if_same_then_else)]
|
||||
if self.handle_movement_event(frame, event).await {
|
||||
if self.handle_movement_input_event(frame, event).await {
|
||||
true
|
||||
} else if self.handle_action_event(event, id.as_ref()).await {
|
||||
} else if self.handle_action_input_event(event, id.as_ref()).await {
|
||||
true
|
||||
} else if can_compose {
|
||||
self.handle_edit_initiating_event(event, id).await
|
||||
self.handle_edit_initiating_input_event(event, id).await
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
@ -223,7 +223,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
util::list_editor_key_bindings(bindings, |_| true, true);
|
||||
}
|
||||
|
||||
fn handle_editor_event(
|
||||
fn handle_editor_input_event(
|
||||
&mut self,
|
||||
terminal: &mut Terminal,
|
||||
crossterm_lock: &Arc<FairMutex<()>>,
|
||||
|
|
@ -251,7 +251,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
}
|
||||
|
||||
_ => {
|
||||
let handled = util::handle_editor_event(
|
||||
let handled = util::handle_editor_input_event(
|
||||
&self.editor,
|
||||
terminal,
|
||||
crossterm_lock,
|
||||
|
|
@ -282,7 +282,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
}
|
||||
}
|
||||
|
||||
async fn handle_event(
|
||||
async fn handle_input_event(
|
||||
&mut self,
|
||||
terminal: &mut Terminal,
|
||||
crossterm_lock: &Arc<FairMutex<()>>,
|
||||
|
|
@ -292,7 +292,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
match &self.cursor {
|
||||
Cursor::Bottom => {
|
||||
if self
|
||||
.handle_normal_event(terminal.frame(), event, can_compose, None)
|
||||
.handle_normal_input_event(terminal.frame(), event, can_compose, None)
|
||||
.await
|
||||
{
|
||||
Reaction::Handled
|
||||
|
|
@ -303,7 +303,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
Cursor::Msg(id) => {
|
||||
let id = id.clone();
|
||||
if self
|
||||
.handle_normal_event(terminal.frame(), event, can_compose, Some(id))
|
||||
.handle_normal_input_event(terminal.frame(), event, can_compose, Some(id))
|
||||
.await
|
||||
{
|
||||
Reaction::Handled
|
||||
|
|
@ -314,7 +314,7 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
Cursor::Editor {
|
||||
coming_from,
|
||||
parent,
|
||||
} => self.handle_editor_event(
|
||||
} => self.handle_editor_input_event(
|
||||
terminal,
|
||||
crossterm_lock,
|
||||
event,
|
||||
|
|
@ -322,7 +322,10 @@ impl<M: Msg, S: MsgStore<M>> InnerTreeViewState<M, S> {
|
|||
parent.clone(),
|
||||
),
|
||||
Cursor::Pseudo { .. } => {
|
||||
if self.handle_movement_event(terminal.frame(), event).await {
|
||||
if self
|
||||
.handle_movement_input_event(terminal.frame(), event)
|
||||
.await
|
||||
{
|
||||
Reaction::Handled
|
||||
} else {
|
||||
Reaction::NotHandled
|
||||
|
|
@ -365,7 +368,7 @@ impl<M: Msg, S: MsgStore<M>> TreeViewState<M, S> {
|
|||
self.0.lock().await.list_key_bindings(bindings, can_compose);
|
||||
}
|
||||
|
||||
pub async fn handle_event(
|
||||
pub async fn handle_input_event(
|
||||
&mut self,
|
||||
terminal: &mut Terminal,
|
||||
crossterm_lock: &Arc<FairMutex<()>>,
|
||||
|
|
@ -375,7 +378,7 @@ impl<M: Msg, S: MsgStore<M>> TreeViewState<M, S> {
|
|||
self.0
|
||||
.lock()
|
||||
.await
|
||||
.handle_event(terminal, crossterm_lock, event, can_compose)
|
||||
.handle_input_event(terminal, crossterm_lock, event, can_compose)
|
||||
.await
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue