mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 07:35:02 +00:00
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.
This commit is contained in:
@@ -113,7 +113,8 @@ pub trait ItemSource<K>: DisplayOrder<K> {
|
||||
|
||||
/// `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<usize> {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -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:?}");
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ impl<C: Collection> 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<C::Key> = 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))),
|
||||
|
||||
@@ -175,8 +175,8 @@ impl<C: Collection> 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<usize>) {
|
||||
if !props.deletable {
|
||||
@@ -185,9 +185,7 @@ impl<C: Collection> 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.
|
||||
|
||||
@@ -100,6 +100,17 @@ impl<C: Collection> 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<C::Key> {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user