Skip to content

Commit 1e3c3da

Browse files
0HyperCubeKeavon
andauthored
Fix the Path tool erroneously showing editable geometry overlays belonging to hidden Path nodes (#2932)
* Ignore hidden path nodes * Use correct path node vector modification * Break test * Better fix for test * Fix rustfmt --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent c42011f commit 1e3c3da

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

editor/src/messages/portfolio/document/utility_types/document_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl DocumentMetadata {
9090

9191
let mut use_local = true;
9292
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, network_interface);
93-
if let Some(path_node) = graph_layer.upstream_node_id_from_name("Path") {
93+
if let Some(path_node) = graph_layer.upstream_visible_node_id_from_name_in_layer("Path") {
9494
if let Some(&source) = self.first_instance_source_ids.get(&layer.to_node()) {
9595
if !network_interface
9696
.upstream_flow_back_from_nodes(vec![path_node], &[], FlowType::HorizontalFlow)

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,12 +3445,17 @@ impl NodeNetworkInterface {
34453445
pub fn compute_modified_vector(&self, layer: LayerNodeIdentifier) -> Option<VectorData> {
34463446
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, self);
34473447

3448-
if let Some(vector_data) = graph_layer.upstream_node_id_from_name("Path").and_then(|node| self.document_metadata.vector_modify.get(&node)) {
3449-
let mut modified = vector_data.clone();
3450-
if let Some(TaggedValue::VectorModification(modification)) = graph_layer.find_input("Path", 1) {
3451-
modification.apply(&mut modified);
3448+
if let Some(path_node) = graph_layer.upstream_visible_node_id_from_name_in_layer("Path") {
3449+
if let Some(vector_data) = self.document_metadata.vector_modify.get(&path_node) {
3450+
let mut modified = vector_data.clone();
3451+
3452+
let path_node = self.document_network().nodes.get(&path_node);
3453+
let modification_input = path_node.and_then(|node: &DocumentNode| node.inputs.get(1)).and_then(|input| input.as_value());
3454+
if let Some(TaggedValue::VectorModification(modification)) = modification_input {
3455+
modification.apply(&mut modified);
3456+
}
3457+
return Some(modified);
34523458
}
3453-
return Some(modified);
34543459
}
34553460

34563461
self.document_metadata

editor/src/messages/tool/common_functionality/graph_modification_utils.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,16 @@ impl<'a> NodeGraphLayer<'a> {
433433
.find(|node_id| self.network_interface.reference(node_id, &[]).is_some_and(|reference| *reference == Some(node_name.to_string())))
434434
}
435435

436+
/// Node id of a visible node if it exists in the layer's primary flow until another layer
437+
pub fn upstream_visible_node_id_from_name_in_layer(&self, node_name: &str) -> Option<NodeId> {
438+
// `.skip(1)` is used to skip self
439+
self.horizontal_layer_flow()
440+
.skip(1)
441+
.take_while(|node_id| !self.network_interface.is_layer(node_id, &[]))
442+
.filter(|node_id| self.network_interface.is_visible(node_id, &[]))
443+
.find(|node_id| self.network_interface.reference(node_id, &[]).is_some_and(|reference| *reference == Some(node_name.to_string())))
444+
}
445+
436446
/// Node id of a protonode if it exists in the layer's primary flow
437447
pub fn upstream_node_id_from_protonode(&self, protonode_identifier: ProtoNodeIdentifier) -> Option<NodeId> {
438448
self.horizontal_layer_flow()
@@ -447,10 +457,11 @@ impl<'a> NodeGraphLayer<'a> {
447457

448458
/// Find all of the inputs of a specific node within the layer's primary flow, up until the next layer is reached.
449459
pub fn find_node_inputs(&self, node_name: &str) -> Option<&'a Vec<NodeInput>> {
460+
// `.skip(1)` is used to skip self
450461
self.horizontal_layer_flow()
451-
.skip(1)// Skip self
452-
.take_while(|node_id| !self.network_interface.is_layer(node_id,&[]))
453-
.find(|node_id| self.network_interface.reference(node_id,&[]).is_some_and(|reference| *reference == Some(node_name.to_string())))
462+
.skip(1)
463+
.take_while(|node_id| !self.network_interface.is_layer(node_id, &[]))
464+
.find(|node_id| self.network_interface.reference(node_id, &[]).is_some_and(|reference| *reference == Some(node_name.to_string())))
454465
.and_then(|node_id| self.network_interface.document_network().nodes.get(&node_id).map(|node| &node.inputs))
455466
}
456467

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ fn extend_path_with_next_segment(tool_data: &mut FreehandToolData, position: DVe
356356
mod test_freehand {
357357
use crate::messages::input_mapper::utility_types::input_mouse::{EditorMouseState, MouseKeys, ScrollDelta};
358358
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
359-
use crate::messages::tool::common_functionality::graph_modification_utils::get_stroke_width;
359+
use crate::messages::tool::common_functionality::graph_modification_utils::{NodeGraphLayer, get_stroke_width};
360360
use crate::messages::tool::tool_messages::freehand_tool::FreehandOptionsUpdate;
361361
use crate::test_utils::test_prelude::*;
362362
use glam::{DAffine2, DVec2};
@@ -368,6 +368,10 @@ mod test_freehand {
368368

369369
layers
370370
.filter_map(|layer| {
371+
let graph_layer = NodeGraphLayer::new(layer, &document.network_interface);
372+
// Only get layers with path nodes
373+
let _ = graph_layer.upstream_visible_node_id_from_name_in_layer("Path")?;
374+
371375
let vector_data = document.network_interface.compute_modified_vector(layer)?;
372376
let transform = document.metadata().transform_to_viewport(layer);
373377
Some((vector_data, transform))
@@ -376,25 +380,15 @@ mod test_freehand {
376380
}
377381

378382
fn verify_path_points(vector_data_list: &[(VectorData, DAffine2)], expected_captured_points: &[DVec2], tolerance: f64) -> Result<(), String> {
379-
if vector_data_list.len() == 0 {
380-
return Err("No vector data found after drawing".to_string());
381-
}
383+
assert_eq!(vector_data_list.len(), 1, "there should be one vector data");
382384

383385
let path_data = vector_data_list.iter().find(|(data, _)| data.point_domain.ids().len() > 0).ok_or("Could not find path data")?;
384386

385387
let (vector_data, transform) = path_data;
386388
let point_count = vector_data.point_domain.ids().len();
387389
let segment_count = vector_data.segment_domain.ids().len();
388390

389-
let actual_positions: Vec<DVec2> = vector_data
390-
.point_domain
391-
.ids()
392-
.iter()
393-
.filter_map(|&point_id| {
394-
let position = vector_data.point_domain.position_from_id(point_id)?;
395-
Some(transform.transform_point2(position))
396-
})
397-
.collect();
391+
let actual_positions: Vec<DVec2> = vector_data.point_domain.positions().iter().map(|&position| transform.transform_point2(position)).collect();
398392

399393
if segment_count != point_count - 1 {
400394
return Err(format!("Expected segments to be one less than points, got {} segments for {} points", segment_count, point_count));

0 commit comments

Comments
 (0)