mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-21 21:09:42 +00:00
make right click close floating windows
This commit is contained in:
parent
55e547f9d0
commit
778372bb4a
|
@ -4,6 +4,8 @@ use ratatui::{
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::event::MouseButton;
|
||||||
|
use crate::event::MouseEventKind;
|
||||||
use crate::hint::Shortcut;
|
use crate::hint::Shortcut;
|
||||||
|
|
||||||
pub trait FloatContent {
|
pub trait FloatContent {
|
||||||
|
@ -54,8 +56,11 @@ impl<Content: FloatContent + ?Sized> Float<Content> {
|
||||||
self.content.draw(frame, popup_area);
|
self.content.draw(frame, popup_area);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_mouse_event(&mut self, event: &MouseEvent) {
|
pub fn handle_mouse_event(&mut self, event: &MouseEvent) -> bool {
|
||||||
self.content.handle_mouse_event(event);
|
match event.kind {
|
||||||
|
MouseEventKind::Down(MouseButton::Right) => true,
|
||||||
|
_ => self.content.handle_mouse_event(event),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the floating window is finished.
|
// Returns true if the floating window is finished.
|
||||||
|
|
|
@ -495,6 +495,23 @@ impl AppState {
|
||||||
return true;
|
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) {
|
if matches!(self.focus, Focus::TabList | Focus::List | Focus::Search) {
|
||||||
let position = Position::new(event.column, event.row);
|
let position = Position::new(event.column, event.row);
|
||||||
let mouse_in_tab_list = self.areas.as_ref().unwrap().tab_list.contains(position);
|
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) {
|
if matches!(self.focus, Focus::Search) {
|
||||||
self.exit_search();
|
self.exit_search();
|
||||||
}
|
}
|
||||||
self.focus = Focus::List;
|
self.focus = Focus::TabList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MouseButton::Right if mouse_in_list => {
|
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
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user