From 51d1c4eeacec6e4baf095fae8c5095b768391e93 Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Thu, 9 Jan 2025 20:37:39 -0800 Subject: [PATCH] Fix drawing new layers not being put next to nested selected layers A regression introduced in #2110 --- .../portfolio/document/document_message_handler.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 0be6fa68..a1775eaf 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -1654,9 +1654,18 @@ impl DocumentMessageHandler { /// Finds the artboard that bounds the point in viewport space and be the container of any newly added layers. pub fn new_layer_bounding_artboard(&self, ipp: &InputPreprocessorMessageHandler) -> LayerNodeIdentifier { - self.click_xray(ipp) + let container_based_on_selection = self.new_layer_parent(true); + + let container_based_on_clicked_artboard = self + .click_xray(ipp) .find(|layer| self.network_interface.is_artboard(&layer.to_node(), &[])) - .unwrap_or(LayerNodeIdentifier::ROOT_PARENT) + .unwrap_or(LayerNodeIdentifier::ROOT_PARENT); + + if container_based_on_selection.ancestors(self.metadata()).any(|ancestor| ancestor == container_based_on_clicked_artboard) { + container_based_on_selection + } else { + container_based_on_clicked_artboard + } } /// Finds the parent folder which, based on the current selections, should be the container of any newly added layers.