diff --git a/crates/layers/src/ui/panel/body.rs b/crates/layers/src/ui/panel/body.rs index 5cc5cc9d2..4624d69d4 100644 --- a/crates/layers/src/ui/panel/body.rs +++ b/crates/layers/src/ui/panel/body.rs @@ -47,8 +47,13 @@ pub(super) fn show_body( let tree = cx.tree; let order = rows.keys(); let mut selection = list_selection(cx, session); - let reveal_key = - reveal.target.clone().filter(|id| order.iter().any(|key| matches!(key, LayerRowKey::Layer(k) if k == id))).map(LayerRowKey::Layer); + // The reveal moves the lead, so a layer revealed with a sub-row of its own selected reveals that row. + let reveal_key = reveal.target.clone().filter(|id| order.iter().any(|key| matches!(key, LayerRowKey::Layer(k) if k == id))).map(|id| { + match &cx.selection.sub_row { + Some(row) if *row.layer() == id && order.contains(row) => row.clone(), + _ => LayerRowKey::Layer(id), + } + }); let eye = cx.visibility_key.map_or(ToggleColumn::sweepable(), |key| ToggleColumn::sweepable().key(key)); let mut columns = vec![ColumnSpec::new(EYE, Label::Empty, ColumnWidth::Controls(1.0)).kind(ColumnKind::Toggle(eye)).icon(IconId::new("eye"))]; diff --git a/crates/layers/src/ui/panel/body/map.rs b/crates/layers/src/ui/panel/body/map.rs index b12152f25..129737b9f 100644 --- a/crates/layers/src/ui/panel/body/map.rs +++ b/crates/layers/src/ui/panel/body/map.rs @@ -49,10 +49,11 @@ pub(super) fn map_events( for event in list { match event { CollectionEvent::Selection(change) => { - let (row, mapped) = match change { - SelectionChange::Set(keys) => (keys.last().cloned(), SelectionChange::Set(layers_of(&keys))), - SelectionChange::Toggle(key) => (Some(key.clone()), SelectionChange::Toggle(key.layer().clone())), - SelectionChange::Clear => (None, SelectionChange::Clear), + // A set made on an effects or Smart Filter row names that row; a toggle acts on its layer only. + let (row, set, mapped) = match change { + SelectionChange::Set(keys) => (keys.last().cloned(), true, SelectionChange::Set(layers_of(&keys))), + SelectionChange::Toggle(key) => (Some(key.clone()), false, SelectionChange::Toggle(key.layer().clone())), + SelectionChange::Clear => (None, false, SelectionChange::Clear), _ => continue, }; let mut part = None; @@ -68,7 +69,11 @@ pub(super) fn map_events( } part = Some(hit); } - events.push(LayersEvent::Select(LayerSelect::new(mapped, part))); + let mut select = LayerSelect::new(mapped, part); + if set && let Some(row) = &row { + select = select.on_row(row); + } + events.push(LayersEvent::Select(select)); } CollectionEvent::Activate(row) => { let on = clicks @@ -100,7 +105,7 @@ pub(super) fn map_events( session.menu = Some(OpenMenu::Eye { rows, current }); } else if plain { if !selected { - events.push(LayersEvent::Select(LayerSelect::new(SelectionChange::Set(vec![layer.clone()]), None))); + events.push(LayersEvent::Select(LayerSelect::new(SelectionChange::Set(vec![layer.clone()]), None).on_row(&request.key))); session.produced = vec![layer.clone()]; session.anchor = Some(LayerRowKey::Layer(layer)); } @@ -154,7 +159,7 @@ pub(super) fn map_events( events.push(if thumb_click_replaces_select(part, *mods, &info) { LayersEvent::ThumbClick { layer: row.layer().clone(), part, mods: *mods } } else { - LayersEvent::Select(LayerSelect::new(SelectionChange::Set(vec![row.layer().clone()]), Some(part))) + LayersEvent::Select(LayerSelect::new(SelectionChange::Set(vec![row.layer().clone()]), Some(part)).on_row(row)) }); } } diff --git a/crates/layers/src/ui/panel/body/rows.rs b/crates/layers/src/ui/panel/body/rows.rs index 9296a2107..8096259ac 100644 --- a/crates/layers/src/ui/panel/body/rows.rs +++ b/crates/layers/src/ui/panel/body/rows.rs @@ -224,11 +224,13 @@ pub(in crate::ui::panel) fn reveal_plan( RevealPlan { target: active.cloned().filter(|_| changed), opens } } -/// The tree's selection as the list holds it: the selected layers, the active one as the lead, and the -/// anchor the last pick left while the selection is still what that pick produced. +/// The tree's selection as the list holds it: the selected layers and the sub-row selected on its own, that row or +/// else the active layer as the lead, and the anchor the last pick left while the selection is still what that pick +/// produced. pub(super) fn list_selection(cx: &PanelContext<'_, T>, session: &Session) -> Selection> { - let items: Vec> = cx.selection.layers.iter().cloned().map(LayerRowKey::Layer).collect(); - let lead = cx.selection.active.clone().map(LayerRowKey::Layer); + let mut items: Vec> = cx.selection.layers.iter().cloned().map(LayerRowKey::Layer).collect(); + items.extend(cx.selection.sub_row.clone()); + let lead = cx.selection.sub_row.clone().or_else(|| cx.selection.active.clone().map(LayerRowKey::Layer)); let same = session.produced.len() == cx.selection.layers.len() && session.produced.iter().all(|id| cx.selection.layers.contains(id)); let anchor = session.anchor.clone().filter(|_| same).or_else(|| lead.clone()); Selection::new(items, lead, anchor) diff --git a/crates/layers/src/ui/panel/events.rs b/crates/layers/src/ui/panel/events.rs index 8bae336f7..fce4871f5 100644 --- a/crates/layers/src/ui/panel/events.rs +++ b/crates/layers/src/ui/panel/events.rs @@ -145,12 +145,24 @@ pub struct LayerSelect { /// The thumbnail the click landed on, which becomes the target; `None` elsewhere on the row /// and for keys (the target stays). pub part: Option, + /// The effects or Smart Filter row a click, a right-click or a selection key picked, which the app may select on + /// its own ([`LayerSelection::sub_row`](crate::ui::tree::LayerSelection::sub_row)); `None` on a layer row. + pub row: Option>, } impl LayerSelect { - /// A selection change with an optional thumbnail target. + /// A selection change with an optional thumbnail target, made on a layer row. pub fn new(change: SelectionChange, part: Option) -> Self { - Self { change, part } + Self { change, part, row: None } + } + + /// The change made on `row`; a layer row leaves [`row`](Self::row) `None`. + pub fn on_row(mut self, row: &LayerRowKey) -> Self + where + Id: Clone, + { + self.row = (!row.is_layer()).then(|| row.clone()); + self } } diff --git a/crates/layers/src/ui/panel/stories.rs b/crates/layers/src/ui/panel/stories.rs index 9f5f1b4a2..16ae93597 100644 --- a/crates/layers/src/ui/panel/stories.rs +++ b/crates/layers/src/ui/panel/stories.rs @@ -16,7 +16,7 @@ use craft_ui::primitives::IconSpec; /// The sample tree with the masked layer active and its mask targeted. fn selected() -> FakeLayers { let mut tree = FakeLayers::sample(); - tree.selection = LayerSelection { layers: vec![3], active: Some(3), target: LayerPart::LayerMask }; + tree.selection = LayerSelection::new(vec![3], Some(3), LayerPart::LayerMask); tree } diff --git a/crates/layers/src/ui/tree.rs b/crates/layers/src/ui/tree.rs index ffa42a752..55c1c0524 100644 --- a/crates/layers/src/ui/tree.rs +++ b/crates/layers/src/ui/tree.rs @@ -118,7 +118,7 @@ pub struct LayerInfo { /// The layer's locks: any of them shows the lock indicator. pub locks: LayerLocks, /// The Background: it can't move below another layer, isn't renamed in place (a double click - /// on its name reports [`ActivateOn::Name`](super::panel::ActivateOn::Name)) and greys blend, + /// on its name reports [`ActivateOn::Row`](super::panel::ActivateOn::Row)) and greys blend, /// opacity and fill. pub background: bool, /// Whether a double click or F2 renames the layer in place. @@ -317,18 +317,21 @@ pub struct LayerSelection { pub active: Option, /// The active layer's part edits go to: its thumbnail gets the target brackets. pub target: LayerPart, + /// An effects or Smart Filter row selected on its own (PhotoCraft's selected Smart Filter, which Delete removes): + /// highlighted beside its layer's row and holding the lead. `None` when only layers are selected. + pub sub_row: Option>, } impl LayerSelection { /// The `layers` selected, `active` the one the property rows show, edits going to `target`. pub fn new(layers: Vec, active: Option, target: LayerPart) -> Self { - Self { layers, active, target } + Self { layers, active, target, sub_row: None } } } impl Default for LayerSelection { fn default() -> Self { - Self { layers: Vec::new(), active: None, target: LayerPart::Pixels } + Self { layers: Vec::new(), active: None, target: LayerPart::Pixels, sub_row: None } } }