From 70dfca7f242c52f61b2c2db746fa097eb87b7354 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 21:43:08 +0000 Subject: [PATCH] Lists: a drag or Delete of a selected sub-row takes the selected sub-rows only A sub-row belongs to the row above it, so a gesture on one acts on the selected rows of its own kind. The Layers panel keeps a Smart Filter row selected beside its layer; a drag of that row carried the layer too, and the drop rule refused the mixed set. --- crates/behavior/src/item_source.rs | 3 ++- crates/layers/tests/it/panel_rows.rs | 14 +++++++++++++- crates/ui-contract/src/contract/items/drag.rs | 2 +- crates/ui-contract/src/contract/items/keys.rs | 8 +++----- crates/ui-contract/src/contract/items/rows.rs | 11 +++++++++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/crates/behavior/src/item_source.rs b/crates/behavior/src/item_source.rs index edaa814c2..3447478c7 100644 --- a/crates/behavior/src/item_source.rs +++ b/crates/behavior/src/item_source.rs @@ -113,7 +113,8 @@ pub trait ItemSource: DisplayOrder { /// `Some(steps)` when entry `at` is a sub-row of an entry above it (a layer's effects): a compact row whose toggle /// cells sit in its content, `steps` indent steps from its start, instead of in their columns (`sub_row_cells`). - /// A press flips them there, and a sweep down the toggle columns passes them by. + /// A press flips them there, and a sweep down the toggle columns passes them by. A drag or Delete of a selected + /// sub-row takes the selected sub-rows only, and one of any other selected row the selected rows that are not sub-rows. fn sub_row(&self, _at: usize) -> Option { None } diff --git a/crates/layers/tests/it/panel_rows.rs b/crates/layers/tests/it/panel_rows.rs index 7d26c137d..50082ac96 100644 --- a/crates/layers/tests/it/panel_rows.rs +++ b/crates/layers/tests/it/panel_rows.rs @@ -244,7 +244,8 @@ fn a_double_click_in_one_frame_selects_a_smart_filter_row_and_activates_it() { } /// A Smart Filter row dragged onto another smart object's row moves the filter there, with the active layer changing to -/// the filter's smart object when the press selects its row. +/// the filter's smart object when the press selects its row. With the filter row selected beside its layer, a drag of +/// the layer's row carries the layer alone. #[trial] fn a_smart_filter_row_dragged_onto_another_smart_object_moves_there() { let mut tree = tree(); @@ -264,4 +265,15 @@ fn a_smart_filter_row_dragged_onto_another_smart_object_moves_there() { }) .collect(); assert_eq!(transfers, [(vec![LayerRowKey::Filters(SMART, Some(0))], other, false)], "{events:?}"); + let from = node(&fixture, "Smart Object").center(); + fixture.drag_hold_at(from, to - from).release_at(to).idle(2); + let events = take(&app); + let moved: Vec<_> = events + .iter() + .filter_map(|event| match event { + LayersEvent::Drop(EditEvent::Set { after: LayerDrop::Layers(mv), .. }) => Some(mv.layers.clone()), + _ => None, + }) + .collect(); + assert_eq!(moved, [vec![SMART]], "{events:?}"); } diff --git a/crates/ui-contract/src/contract/items/drag.rs b/crates/ui-contract/src/contract/items/drag.rs index 58a7ab458..d9c269612 100644 --- a/crates/ui-contract/src/contract/items/drag.rs +++ b/crates/ui-contract/src/contract/items/drag.rs @@ -408,7 +408,7 @@ impl ItemsHooks<'_, '_, C> { fn begin_row_drag(&mut self, cx: &mut Cx<'_, C>, props: &CollectionProps, at: usize) { let id = cx.core.id; let key = self.source.key(at); - let keys: Vec = if self.holds(at) { self.selected_keys(&self.selection) } else { vec![key.clone()] }; + let keys = self.acted_on(at); let count = keys.len() as u64; let preview = match props.drag_count { Some(word) => DragPreview::Badge(Label::from(cx.env.counted(word, count))), diff --git a/crates/ui-contract/src/contract/items/keys.rs b/crates/ui-contract/src/contract/items/keys.rs index 6e40ed3cf..1b6041034 100644 --- a/crates/ui-contract/src/contract/items/keys.rs +++ b/crates/ui-contract/src/contract/items/keys.rs @@ -175,8 +175,8 @@ impl ItemsHooks<'_, '_, C> { } } - /// Delete and Backspace at the lead of a `deletable` collection: the request names the selected items when the lead - /// is one of them, else the lead alone. The keys stay untaken (shortcut candidates) in a collection that is not + /// Delete and Backspace at the lead of a `deletable` collection: the request names the selected items of the lead's + /// kind (rows or sub-rows) when the lead is one of them, else the lead alone. The keys stay untaken (shortcut candidates) in a collection that is not /// `deletable`. pub(super) fn delete_key(&mut self, cx: &mut Cx<'_, C>, props: &CollectionProps, lead_at: Option) { if !props.deletable { @@ -185,9 +185,7 @@ impl ItemsHooks<'_, '_, C> { let forward = cx.core.intents.take_exact(&Intent::delete(true, Granularity::Unit)); let back = cx.core.intents.take_exact(&Intent::delete(false, Granularity::Unit)); let Some(row) = lead_at.filter(|_| forward || back) else { return }; - let lead = self.source.key(row); - let keys = if self.holds(row) { self.selected_keys(&self.selection) } else { vec![lead] }; - self.events.push(CollectionEvent::Delete(keys)); + self.events.push(CollectionEvent::Delete(self.acted_on(row))); } /// Space on the lead row `row`, as `CollectionProps.space` says. diff --git a/crates/ui-contract/src/contract/items/rows.rs b/crates/ui-contract/src/contract/items/rows.rs index 875c0e6e6..fc52939f5 100644 --- a/crates/ui-contract/src/contract/items/rows.rs +++ b/crates/ui-contract/src/contract/items/rows.rs @@ -100,6 +100,17 @@ impl ItemsHooks<'_, '_, C> { selection.placed(self.source).rows().into_iter().map(|at| self.source.key(at)).collect() } + /// The keys a gesture on the row at `at` acts on, in the display order: the selected rows of its kind when the + /// selection holds it (sub-rows for a sub-row, the other rows for any other row), else that row alone. A sub-row + /// belongs to the row above it, so the two kinds never move or go together. + pub(super) fn acted_on(&self, at: usize) -> Vec { + if !self.holds(at) { + return vec![self.source.key(at)]; + } + let sub = self.source.sub_row(at).is_some(); + self.placed().rows().into_iter().filter(|row| self.source.sub_row(*row).is_some() == sub).map(|row| self.source.key(row)).collect() + } + /// A pick of the rows `from` to `to` in a model of cells: one range of whole rows (the rows' cells in every column /// of the layout), active and anchored at its first cell. pub(super) fn select_rows(&mut self, comp: &C, from: usize, to: usize) {