diff --git a/tui/src/confirmation.rs b/tui/src/confirmation.rs index 2ed5898b..4b0c16f3 100644 --- a/tui/src/confirmation.rs +++ b/tui/src/confirmation.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use crate::{float::FloatContent, hint::Shortcut}; use ratatui::{ - crossterm::event::{KeyCode, KeyEvent, MouseEvent, MouseEventKind}, + crossterm::event::{KeyCode, KeyEvent, MouseButton, MouseEvent, MouseEventKind}, layout::Alignment, prelude::*, widgets::{Block, Borders, Clear, List}, @@ -87,15 +87,20 @@ impl FloatContent for ConfirmPrompt { fn handle_mouse_event(&mut self, event: &MouseEvent) -> bool { match event.kind { + MouseEventKind::Down(MouseButton::Left) => { + self.status = ConfirmStatus::Confirm; + true + } MouseEventKind::ScrollDown => { self.scroll_down(); + false } MouseEventKind::ScrollUp => { self.scroll_up(); + false } - _ => {} + _ => false, } - false } fn handle_key_event(&mut self, key: &KeyEvent) -> bool { diff --git a/tui/src/state.rs b/tui/src/state.rs index eaa582a7..7b02d405 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -483,7 +483,7 @@ impl AppState { match &mut self.focus { Focus::FloatingWindow(float) => float.draw(frame, chunks[1]), - Focus::ConfirmationPrompt(prompt) => prompt.draw(frame, chunks[1]), + Focus::ConfirmationPrompt(confirm) => confirm.draw(frame, chunks[1]), _ => {} } @@ -502,12 +502,25 @@ impl AppState { } return true; } - Focus::ConfirmationPrompt(prompt) => { - if prompt.handle_mouse_event(event) { - self.focus = Focus::List; - self.selected_commands.clear(); + Focus::ConfirmationPrompt(confirm) => { + if confirm.handle_mouse_event(event) { + match confirm.content.status { + ConfirmStatus::Abort => { + self.focus = Focus::List; + if !self.multi_select { + self.selected_commands.clear() + } else { + if let Some(node) = self.get_selected_node() { + if !node.multi_select { + self.selected_commands.retain(|cmd| cmd.name != node.name); + } + } + } + } + ConfirmStatus::Confirm => self.handle_confirm_command(), + ConfirmStatus::None => {} + } } - return true; } _ => {} }