diff --git a/editor/src/messages/tool/common_functionality/path_outline.rs b/editor/src/messages/tool/common_functionality/path_outline.rs index 80010348..e210efa5 100644 --- a/editor/src/messages/tool/common_functionality/path_outline.rs +++ b/editor/src/messages/tool/common_functionality/path_outline.rs @@ -21,7 +21,7 @@ pub struct PathOutline { impl PathOutline { /// Creates an outline of a layer either with a pre-existing overlay or by generating a new one - fn create_outline( + fn try_create_outline( document_layer_path: Vec, overlay_path: Option>, document: &DocumentMessageHandler, @@ -72,6 +72,28 @@ impl PathOutline { Some(overlay) } + /// Creates an outline of a layer either with a pre-existing overlay or by generating a new one + /// + /// Creates an outline, discarding the overlay on failiure + fn create_outline( + document_layer_path: Vec, + overlay_path: Option>, + document: &DocumentMessageHandler, + responses: &mut VecDeque, + font_cache: &FontCache, + ) -> Option> { + let copied_overlay_path = overlay_path.clone(); + let result = Self::try_create_outline(document_layer_path, overlay_path, document, responses, font_cache); + if result.is_none() { + // Discard the overlay layer if it exists + if let Some(overlay_path) = copied_overlay_path { + let operation = Operation::DeleteLayer { path: overlay_path }; + responses.push_back(DocumentMessage::Overlays(operation.into()).into()); + } + } + result + } + /// Removes the hovered overlay and deletes path references pub fn clear_hovered(&mut self, responses: &mut VecDeque) { if let Some(path) = self.hovered_overlay_path.take() {