From 1a2a0e87576b4e03040e9dee7740c6ec857bdac7 Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Sat, 16 Mar 2024 00:30:29 -0700 Subject: [PATCH] Minor code cleanup and spelling fix --- .../document/document_message_handler.rs | 6 ++-- .../graph_operation_message_handler.rs | 2 +- .../node_graph/node_graph_message_handler.rs | 6 ++-- .../utility_types/document_metadata.rs | 30 +++++++++---------- .../snapping/layer_snapper.rs | 2 +- .../messages/tool/tool_messages/fill_tool.rs | 13 ++++---- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index c2e31ac1..dbb5b5e2 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -493,7 +493,7 @@ impl MessageHandler> for DocumentMessageHand return Some(index as isize); } - for descendant in direct_child.decendants(self.metadata()) { + for descendant in direct_child.descendants(self.metadata()) { if self.selected_nodes.selected_layers(self.metadata()).any(|selected| selected == descendant) { return Some(index as isize); } @@ -918,7 +918,7 @@ impl DocumentMessageHandler { let document_quad = self.metadata.document_to_viewport.inverse() * viewport_quad; self.metadata .root() - .decendants(&self.metadata) + .descendants(&self.metadata) .filter(|&layer| self.selected_nodes.layer_visible(layer, self.network(), self.metadata())) .filter(|&layer| !is_artboard(layer, network)) .filter_map(|layer| self.metadata.click_target(layer).map(|targets| (layer, targets))) @@ -931,7 +931,7 @@ impl DocumentMessageHandler { let point = self.metadata.document_to_viewport.inverse().transform_point2(viewport_location); self.metadata .root() - .decendants(&self.metadata) + .descendants(&self.metadata) .filter(|&layer| self.selected_nodes.layer_visible(layer, self.network(), self.metadata())) .filter_map(|layer| self.metadata.click_target(layer).map(|targets| (layer, targets))) .filter(move |(layer, target)| target.iter().any(|target: &ClickTarget| target.intersect_point(point, self.metadata.transform_to_document(*layer)))) diff --git a/editor/src/messages/portfolio/document/node_graph/graph_operation_message_handler.rs b/editor/src/messages/portfolio/document/node_graph/graph_operation_message_handler.rs index 47b26912..3c64bd30 100644 --- a/editor/src/messages/portfolio/document/node_graph/graph_operation_message_handler.rs +++ b/editor/src/messages/portfolio/document/node_graph/graph_operation_message_handler.rs @@ -517,7 +517,7 @@ impl<'a> ModifyInputsContext<'a> { }; let layer_node = LayerNodeIdentifier::new(id, self.document_network); - let child_layers = layer_node.decendants(self.document_metadata).map(|layer| layer.to_node()).collect::>(); + let child_layers = layer_node.descendants(self.document_metadata).map(|layer| layer.to_node()).collect::>(); layer_node.delete(self.document_metadata); let new_input = node.inputs[1].clone(); diff --git a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs index e9346b9b..589b4bf5 100644 --- a/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs +++ b/editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs @@ -928,9 +928,9 @@ impl<'a> MessageHandler> for NodeGrap } // Shift nodes connected to the output port of the specified node - for &decendant in outwards_links.get(&node_id).unwrap_or(&Vec::new()) { - let shift = required_shift(node_id, decendant, network); - let mut stack = vec![decendant]; + for &descendant in outwards_links.get(&node_id).unwrap_or(&Vec::new()) { + let shift = required_shift(node_id, descendant, network); + let mut stack = vec![descendant]; while let Some(id) = stack.pop() { shift_node(id, shift, network); stack.extend(outwards_links.get(&id).unwrap_or(&Vec::new()).iter().copied()) diff --git a/editor/src/messages/portfolio/document/utility_types/document_metadata.rs b/editor/src/messages/portfolio/document/utility_types/document_metadata.rs index 9eadb5ff..55d0489f 100644 --- a/editor/src/messages/portfolio/document/utility_types/document_metadata.rs +++ b/editor/src/messages/portfolio/document/utility_types/document_metadata.rs @@ -48,8 +48,8 @@ impl DocumentMetadata { LayerNodeIdentifier::ROOT } - pub fn all_layers(&self) -> DecendantsIter<'_> { - self.root().decendants(self) + pub fn all_layers(&self) -> DescendantsIter<'_> { + self.root().descendants(self) } pub fn layer_exists(&self, layer: LayerNodeIdentifier) -> bool { @@ -396,9 +396,9 @@ impl LayerNodeIdentifier { } } - /// Iterator through all decendants, including recursive children (not including self) - pub fn decendants(self, metadata: &DocumentMetadata) -> DecendantsIter { - DecendantsIter { + /// Iterator through all descendants, including recursive children (not including self) + pub fn descendants(self, metadata: &DocumentMetadata) -> DescendantsIter { + DescendantsIter { front: self.first_child(metadata), back: self.last_child(metadata).and_then(|child| child.last_children(metadata).last()), metadata, @@ -488,7 +488,7 @@ impl LayerNodeIdentifier { } let mut delete = vec![self]; - delete.extend(self.decendants(metadata)); + delete.extend(self.descendants(metadata)); for node in delete { metadata.structure.remove(&node); } @@ -533,17 +533,17 @@ impl<'a> Iterator for AxisIter<'a> { } // ============== -// DecendantsIter +// DescendantsIter // ============== #[derive(Clone)] -pub struct DecendantsIter<'a> { +pub struct DescendantsIter<'a> { front: Option, back: Option, metadata: &'a DocumentMetadata, } -impl<'a> Iterator for DecendantsIter<'a> { +impl<'a> Iterator for DescendantsIter<'a> { type Item = LayerNodeIdentifier; fn next(&mut self) -> Option { @@ -561,7 +561,7 @@ impl<'a> Iterator for DecendantsIter<'a> { } } } -impl<'a> DoubleEndedIterator for DecendantsIter<'a> { +impl<'a> DoubleEndedIterator for DescendantsIter<'a> { fn next_back(&mut self) -> Option { if self.front == self.back { self.front = None; @@ -618,7 +618,7 @@ fn test_tree() { assert_eq!(root.children(metadata).collect::>(), vec![LayerNodeIdentifier::new_unchecked(NodeId(3))]); root.push_child(metadata, LayerNodeIdentifier::new_unchecked(NodeId(6))); assert_eq!(root.children(metadata).map(LayerNodeIdentifier::to_node).collect::>(), vec![NodeId(3), NodeId(6)]); - assert_eq!(root.decendants(metadata).map(LayerNodeIdentifier::to_node).collect::>(), vec![NodeId(3), NodeId(6)]); + assert_eq!(root.descendants(metadata).map(LayerNodeIdentifier::to_node).collect::>(), vec![NodeId(3), NodeId(6)]); LayerNodeIdentifier::new_unchecked(NodeId(3)).add_after(metadata, LayerNodeIdentifier::new_unchecked(NodeId(4))); LayerNodeIdentifier::new_unchecked(NodeId(3)).add_before(metadata, LayerNodeIdentifier::new_unchecked(NodeId(2))); LayerNodeIdentifier::new_unchecked(NodeId(6)).add_before(metadata, LayerNodeIdentifier::new_unchecked(NodeId(5))); @@ -631,11 +631,11 @@ fn test_tree() { vec![NodeId(1), NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(6), NodeId(9)] ); assert_eq!( - root.decendants(metadata).map(LayerNodeIdentifier::to_node).collect::>(), + root.descendants(metadata).map(LayerNodeIdentifier::to_node).collect::>(), vec![NodeId(1), NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(6), NodeId(7), NodeId(8), NodeId(9)] ); assert_eq!( - root.decendants(metadata).map(LayerNodeIdentifier::to_node).rev().collect::>(), + root.descendants(metadata).map(LayerNodeIdentifier::to_node).rev().collect::>(), vec![NodeId(9), NodeId(8), NodeId(7), NodeId(6), NodeId(5), NodeId(4), NodeId(3), NodeId(2), NodeId(1)] ); assert!(root.children(metadata).all(|child| child.parent(metadata) == Some(root))); @@ -647,11 +647,11 @@ fn test_tree() { vec![NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(9)] ); assert_eq!( - root.decendants(metadata).map(LayerNodeIdentifier::to_node).collect::>(), + root.descendants(metadata).map(LayerNodeIdentifier::to_node).collect::>(), vec![NodeId(2), NodeId(3), NodeId(4), NodeId(5), NodeId(9), NodeId(10)] ); assert_eq!( - root.decendants(metadata).map(LayerNodeIdentifier::to_node).rev().collect::>(), + root.descendants(metadata).map(LayerNodeIdentifier::to_node).rev().collect::>(), vec![NodeId(10), NodeId(9), NodeId(5), NodeId(4), NodeId(3), NodeId(2)] ); } diff --git a/editor/src/messages/tool/common_functionality/snapping/layer_snapper.rs b/editor/src/messages/tool/common_functionality/snapping/layer_snapper.rs index 27588031..e551a446 100644 --- a/editor/src/messages/tool/common_functionality/snapping/layer_snapper.rs +++ b/editor/src/messages/tool/common_functionality/snapping/layer_snapper.rs @@ -434,7 +434,7 @@ pub fn get_layer_snap_points(layer: LayerNodeIdentifier, snap_data: &SnapData, p let document = snap_data.document; if document.metadata().is_artboard(layer) { } else if document.metadata().is_folder(layer) { - for child in layer.decendants(document.metadata()) { + for child in layer.descendants(document.metadata()) { get_layer_snap_points(child, snap_data, points); } } else { diff --git a/editor/src/messages/tool/tool_messages/fill_tool.rs b/editor/src/messages/tool/tool_messages/fill_tool.rs index 8f62345b..b1cfcf42 100644 --- a/editor/src/messages/tool/tool_messages/fill_tool.rs +++ b/editor/src/messages/tool/tool_messages/fill_tool.rs @@ -92,13 +92,11 @@ impl Fsm for FillToolFsmState { let Some(layer_identifier) = document.click(input.mouse.position, &document.network) else { return self; }; - // TODO: Use a match statement here instead of if-else - let color = if color_event == FillToolMessage::FillPrimaryColor { - global_tool_data.primary_color - } else { - global_tool_data.secondary_color + let fill = match color_event { + FillToolMessage::FillPrimaryColor => Fill::Solid(global_tool_data.primary_color), + FillToolMessage::FillSecondaryColor => Fill::Solid(global_tool_data.secondary_color), + _ => return self, }; - let fill = Fill::Solid(color); responses.add(DocumentMessage::StartTransaction); responses.add(GraphOperationMessage::FillSet { layer: layer_identifier, fill }); @@ -109,7 +107,8 @@ impl Fsm for FillToolFsmState { (FillToolFsmState::Filling, FillToolMessage::PointerUp) => FillToolFsmState::Ready, (FillToolFsmState::Filling, FillToolMessage::Abort) => { responses.add(DocumentMessage::AbortTransaction); - return FillToolFsmState::Ready; + + FillToolFsmState::Ready } _ => self, }