make right click close floating windows

This commit is contained in:
nnyyxxxx 2024-11-13 03:30:56 -05:00
parent 6dae016104
commit 93eb1196e8
No known key found for this signature in database
GPG Key ID: 6038FFD6589902CB
2 changed files with 25 additions and 12 deletions

View File

@ -4,6 +4,8 @@ use ratatui::{
Frame,
};
use crate::event::MouseButton;
use crate::event::MouseEventKind;
use crate::hint::Shortcut;
pub trait FloatContent {
@ -54,8 +56,11 @@ impl<Content: FloatContent + ?Sized> Float<Content> {
self.content.draw(frame, popup_area);
}
pub fn handle_mouse_event(&mut self, event: &MouseEvent) {
self.content.handle_mouse_event(event);
pub fn handle_mouse_event(&mut self, event: &MouseEvent) -> bool {
match event.kind {
MouseEventKind::Down(MouseButton::Right) => true,
_ => self.content.handle_mouse_event(event),
}
}
// Returns true if the floating window is finished.

View File

@ -495,6 +495,23 @@ impl AppState {
return true;
}
match &mut self.focus {
Focus::FloatingWindow(float) => {
if float.handle_mouse_event(event) {
self.focus = Focus::List;
}
return true;
}
Focus::ConfirmationPrompt(prompt) => {
if prompt.handle_mouse_event(event) {
self.focus = Focus::List;
self.selected_commands.clear();
}
return true;
}
_ => {}
}
if matches!(self.focus, Focus::TabList | Focus::List | Focus::Search) {
let position = Position::new(event.column, event.row);
let mouse_in_tab_list = self.areas.as_ref().unwrap().tab_list.contains(position);
@ -561,7 +578,7 @@ impl AppState {
if matches!(self.focus, Focus::Search) {
self.exit_search();
}
self.focus = Focus::List;
self.focus = Focus::TabList;
}
}
MouseButton::Right if mouse_in_list => {
@ -598,15 +615,6 @@ impl AppState {
_ => {}
}
}
match &mut self.focus {
Focus::FloatingWindow(float) => {
float.content.handle_mouse_event(event);
}
Focus::ConfirmationPrompt(confirm) => {
confirm.content.handle_mouse_event(event);
}
_ => {}
}
true
}