mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-24 06:01:55 +00:00
make right click close floating windows
This commit is contained in:
parent
55e547f9d0
commit
778372bb4a
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user