layers: a double click on a thumbnail activates it once

This commit is contained in:
aiongg
2026-11-12 20:37:37 +00:00
parent e1d34a0093
commit 2f7593cbbb
2 changed files with 49 additions and 5 deletions
+11 -5
View File
@@ -29,10 +29,10 @@ pub(super) fn map_events<T: LayerTree>(
events: &mut Vec<LayersEvent<T::Id>>,
) {
let tree = cx.tree;
let clicks: Vec<(LayerRowKey<T::Id>, ThumbTarget, Mods)> = list
let clicks: Vec<(LayerRowKey<T::Id>, ThumbTarget, Mods, u32)> = list
.iter()
.filter_map(|event| match event {
CollectionEvent::Item(key, RowEvent::ThumbClicked { target, mods, .. }) => Some((key.clone(), *target, *mods)),
CollectionEvent::Item(key, RowEvent::ThumbClicked { target, mods, clicks, .. }) => Some((key.clone(), *target, *mods, *clicks)),
_ => None,
})
.collect();
@@ -58,7 +58,7 @@ pub(super) fn map_events<T: LayerTree>(
};
let mut part = None;
if let Some(row) = &row
&& let Some(at) = clicks.iter().enumerate().position(|(i, click)| click.0 == *row && !used[i])
&& let Some(at) = clicks.iter().enumerate().position(|(i, click)| click.0 == *row && click.3 < 2 && !used[i])
{
used[at] = true;
let info = tree.info(row.layer());
@@ -75,6 +75,8 @@ pub(super) fn map_events<T: LayerTree>(
}
events.push(LayersEvent::Select(select));
}
// A double click on a thumbnail is reported once, by its own click.
CollectionEvent::Activate(row) if clicks.iter().any(|click| click.0 == row && click.3 == 2) => {}
CollectionEvent::Activate(row) => {
let on = clicks
.iter()
@@ -165,12 +167,16 @@ pub(super) fn map_events<T: LayerTree>(
}
}
// A thumbnail click that selected nothing new still acts.
for (i, (row, target, mods)) in clicks.iter().enumerate() {
if used[i] || activated.contains(row) {
for (i, (row, target, mods, count)) in clicks.iter().enumerate() {
if used[i] || (activated.contains(row) && *count < 2) {
continue;
}
let info = tree.info(row.layer());
let part = thumb_part(row, &info, *target);
if *count == 2 {
events.push(LayersEvent::Activate { row: row.clone(), on: ActivateOn::Thumbnail(part) });
continue;
}
events.push(if thumb_click_replaces_select(part, *mods, &info) {
LayersEvent::ThumbClick { layer: row.layer().clone(), part, mods: *mods }
} else {
+38
View File
@@ -188,3 +188,41 @@ fn a_frames_mask_thumbnail_drags_the_mask() {
.collect();
assert_eq!(moves, [MaskMove::new(id, LayerPart::LayerMask, 1, false)]);
}
/// The Activate events on a thumbnail among `events`: the layer and the part.
fn thumb_activations(events: &[LayersEvent<u32>]) -> Vec<(LayerRowKey<u32>, LayerPart)> {
events
.iter()
.filter_map(|event| match event {
LayersEvent::Activate { row, on: ActivateOn::Thumbnail(part), .. } => Some((row.clone(), *part)),
_ => None,
})
.collect()
}
/// A double click on a layer's thumbnail activates that thumbnail once; a single click only selects, and a double click on
/// the name activates no thumbnail.
#[trial]
fn a_double_click_on_a_thumbnail_activates_it_once() {
let info = LayerInfo::new("Title", LayerKind::Text);
let (mut fixture, app) = rig(tree());
take(&app);
let row = node(&fixture, "Title").node.into();
let thumb = testing::thumb_rect(fixture.ctx(), row, &info, LayerPart::Pixels).expect("the layer's thumbnail").center();
fixture.click_at(thumb).settle();
let once = take(&app);
assert!(thumb_activations(&once).is_empty(), "one click activates nothing: {once:?}");
assert!(once.iter().any(|event| matches!(event, LayersEvent::Select(_))), "one click selects: {once:?}");
fixture.click_at(thumb).settle();
let twice = take(&app);
assert_eq!(thumb_activations(&twice), [(LayerRowKey::Layer(1), LayerPart::Pixels)], "the double click: {twice:?}");
assert!(
!twice.iter().any(|event| matches!(event, LayersEvent::Activate { on: ActivateOn::Row, .. })),
"the thumbnail is not also a row activation: {twice:?}"
);
let name = node(&fixture, "Smart Object").center();
fixture.click_at(name).settle();
fixture.click_at(name).settle();
let named = take(&app);
assert!(thumb_activations(&named).is_empty(), "a double click on the name is no thumbnail activation: {named:?}");
}