Skip to content

Commit c25e90a

Browse files
committed
fixed deep-select and overlays
1 parent d2fc919 commit c25e90a

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

editor/src/messages/tool/tool_messages/select_tool.rs

+43-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::consts::{
88
use crate::messages::input_mapper::utility_types::input_mouse::ViewportPosition;
99
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
1010
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
11-
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
11+
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
1212
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, FlipAxis, GroupFolderType};
1313
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, NodeNetworkInterface, NodeTemplate};
1414
use crate::messages::portfolio::document::utility_types::nodes::SelectedNodes;
@@ -705,8 +705,14 @@ impl Fsm for SelectToolFsmState {
705705
draw_layer_outline(layer);
706706
}
707707
} else {
708-
for layer in intersection {
709-
draw_layer_outline(layer);
708+
if tool_data.nested_selection_behavior == NestedSelectionBehavior::Deepest {
709+
for layer in intersection.iter().filter(|layer| !layer.has_children(document.metadata())) {
710+
draw_layer_outline(*layer);
711+
}
712+
} else {
713+
for layer in intersection {
714+
draw_layer_outline(layer);
715+
}
710716
}
711717
}
712718

@@ -1387,14 +1393,19 @@ impl Fsm for SelectToolFsmState {
13871393
.collect();
13881394
tool_data.layers_dragging = updated_selection;
13891395
} else if selection_modified {
1396+
let filtered_selections = filter_nested_selection(document.metadata(), &new_selected);
13901397
let parent_selected: HashSet<_> = new_selected
13911398
.into_iter()
13921399
.map(|layer| {
13931400
// Find the parent node
13941401
layer.ancestors(document.metadata()).filter(not_artboard(document)).last().unwrap_or(layer)
13951402
})
13961403
.collect();
1397-
tool_data.layers_dragging.extend(parent_selected.iter().copied());
1404+
if tool_data.nested_selection_behavior == NestedSelectionBehavior::Deepest {
1405+
tool_data.layers_dragging.extend(filtered_selections);
1406+
} else {
1407+
tool_data.layers_dragging.extend(parent_selected.iter().copied());
1408+
}
13981409
}
13991410

14001411
if negative_selection || selection_modified {
@@ -1680,3 +1691,31 @@ pub fn extend_lasso(lasso_polygon: &mut Vec<DVec2>, point: DVec2) {
16801691
lasso_polygon.push(point);
16811692
}
16821693
}
1694+
1695+
pub fn filter_nested_selection(metadata: &DocumentMetadata, new_selected: &HashSet<LayerNodeIdentifier>) -> HashSet<LayerNodeIdentifier> {
1696+
let mut filtered_selection = HashSet::new();
1697+
1698+
// First collect childless layers
1699+
for &layer in new_selected {
1700+
if !layer.has_children(metadata) {
1701+
filtered_selection.insert(layer);
1702+
}
1703+
}
1704+
1705+
// Then process parents with all children selected
1706+
for &layer in new_selected {
1707+
if layer.has_children(metadata) {
1708+
let all_children_selected = layer.children(metadata).all(|child| new_selected.contains(&child));
1709+
1710+
if all_children_selected {
1711+
// Remove all children of the parent
1712+
layer.children(metadata).for_each(|child| {
1713+
filtered_selection.remove(&child);
1714+
});
1715+
// Add the parent
1716+
filtered_selection.insert(layer);
1717+
}
1718+
}
1719+
}
1720+
filtered_selection
1721+
}

0 commit comments

Comments
 (0)