From d48a6d4b433df62c72d7c2b7842747ba0981221e Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Wed, 8 Jan 2025 16:18:49 +0800 Subject: [PATCH] table: Support clear selection (#533) --- crates/ui/src/table.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/ui/src/table.rs b/crates/ui/src/table.rs index 3fdb7f26..2205f011 100644 --- a/crates/ui/src/table.rs +++ b/crates/ui/src/table.rs @@ -410,6 +410,14 @@ where cx.notify(); } + /// Clear the selection of the table. + pub fn clear_selection(&mut self, cx: &mut ViewContext) { + self.selection_state = SelectionState::Row; + self.selected_row = None; + self.selected_col = None; + cx.notify(); + } + fn on_row_click(&mut self, ev: &MouseDownEvent, row_ix: usize, cx: &mut ViewContext) { if ev.button == MouseButton::Right { self.right_clicked_row = Some(row_ix); @@ -431,10 +439,7 @@ where } fn action_cancel(&mut self, _: &Cancel, cx: &mut ViewContext) { - self.selection_state = SelectionState::Row; - self.selected_row = None; - self.selected_col = None; - cx.notify(); + self.clear_selection(cx); } fn action_select_prev(&mut self, _: &SelectPrev, cx: &mut ViewContext) {