table: Support clear selection (#533)

This commit is contained in:
Floyd Wang 2025-01-08 16:18:49 +08:00 committed by GitHub
parent 804705a260
commit d48a6d4b43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -410,6 +410,14 @@ where
cx.notify();
}
/// Clear the selection of the table.
pub fn clear_selection(&mut self, cx: &mut ViewContext<Self>) {
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<Self>) {
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>) {
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<Self>) {