Skip to content

Commit c7176bd

Browse files
committed
Remove on shift for deep
1 parent 223e84b commit c7176bd

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

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

+30-21
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ impl Fsm for SelectToolFsmState {
965965

966966
match tool_data.nested_selection_behavior {
967967
NestedSelectionBehavior::Shallowest if !input.keyboard.key(select_deepest) => drag_shallowest_manipulation(responses, selected, tool_data, document),
968-
_ => drag_deepest_manipulation(responses, selected, tool_data, document),
968+
_ => drag_deepest_manipulation(responses, selected, tool_data, document, false),
969969
}
970970
tool_data.get_snap_candidates(document, input);
971971

@@ -1309,12 +1309,19 @@ impl Fsm for SelectToolFsmState {
13091309
} else if let Some(selecting_layer) = tool_data.select_single_layer.take() {
13101310
// Previously, we may have had many layers selected. If the user clicks without dragging, we should just select the one layer that has been clicked.
13111311
if !has_dragged {
1312-
if selecting_layer == LayerNodeIdentifier::ROOT_PARENT {
1313-
log::error!("selecting_layer should not be ROOT_PARENT");
1314-
} else {
1315-
responses.add(NodeGraphMessage::SelectedNodesSet {
1316-
nodes: vec![selecting_layer.to_node()],
1317-
});
1312+
let intersection_list = document.click_list(input).collect::<Vec<_>>();
1313+
let intersection = document.find_deepest(&intersection_list);
1314+
if let Some(intersection) = intersection {
1315+
tool_data.layer_selected_on_start = Some(intersection);
1316+
let selected = intersection_list;
1317+
1318+
match tool_data.nested_selection_behavior {
1319+
NestedSelectionBehavior::Shallowest => drag_shallowest_manipulation(responses, selected, tool_data, document),
1320+
_ => drag_deepest_manipulation(responses, selected, tool_data, document, true),
1321+
}
1322+
tool_data.get_snap_candidates(document, input);
1323+
1324+
responses.add(DocumentMessage::StartTransaction);
13181325
}
13191326
}
13201327
}
@@ -1621,13 +1628,12 @@ fn drag_shallowest_manipulation(responses: &mut VecDeque<Message>, selected: Vec
16211628
})
16221629
.and_then(|lca| {
16231630
let direct_children_of_lca: Vec<_> = lca.children(metadata).collect();
1624-
if clicked_layer == lca {
1625-
Some(lca)
1626-
} else {
1631+
(clicked_layer == lca).then_some(lca).and_then(|_| {
16271632
direct_children_of_lca
16281633
.iter()
1629-
.find(|&&child| clicked_layer == child || clicked_layer.ancestors(metadata).any(|ancestor| ancestor == child)).copied()
1630-
}
1634+
.find(|&&child| clicked_layer == child || clicked_layer.ancestors(metadata).any(|ancestor| ancestor == child))
1635+
.copied()
1636+
})
16311637
})
16321638
});
16331639

@@ -1650,15 +1656,18 @@ fn drag_shallowest_manipulation(responses: &mut VecDeque<Message>, selected: Vec
16501656
});
16511657
}
16521658

1653-
fn drag_deepest_manipulation(responses: &mut VecDeque<Message>, selected: Vec<LayerNodeIdentifier>, tool_data: &mut SelectToolData, document: &DocumentMessageHandler) {
1654-
tool_data.layers_dragging.append(&mut vec![
1655-
document.find_deepest(&selected).unwrap_or(
1656-
LayerNodeIdentifier::ROOT_PARENT
1657-
.children(document.metadata())
1658-
.next()
1659-
.expect("ROOT_PARENT should have a layer child when clicking"),
1660-
),
1661-
]);
1659+
fn drag_deepest_manipulation(responses: &mut VecDeque<Message>, selected: Vec<LayerNodeIdentifier>, tool_data: &mut SelectToolData, document: &DocumentMessageHandler, remove: bool) {
1660+
let layer = document.find_deepest(&selected).unwrap_or(
1661+
LayerNodeIdentifier::ROOT_PARENT
1662+
.children(document.metadata())
1663+
.next()
1664+
.expect("ROOT_PARENT should have a layer child when clicking"),
1665+
);
1666+
if !remove {
1667+
tool_data.layers_dragging.append(&mut vec![layer]);
1668+
} else {
1669+
tool_data.layers_dragging.retain(|&selected_layer| layer != selected_layer);
1670+
}
16621671
responses.add(NodeGraphMessage::SelectedNodesSet {
16631672
nodes: tool_data
16641673
.layers_dragging

0 commit comments

Comments
 (0)