Skip to content

Commit 119a554

Browse files
authored
Fix the Path tool adding a Path node but not applying the change until a second attempt due to wrong segment IDs (#3727)
* Fix SegmentIds lost when no Path node exists * fix import order * Use Arc<Vector> in vector_data for regression
1 parent e606efd commit 119a554

6 files changed

Lines changed: 32 additions & 5 deletions

File tree

editor/src/messages/portfolio/document/document_message.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use graphene_std::Color;
1515
use graphene_std::raster::BlendMode;
1616
use graphene_std::raster::Image;
1717
use graphene_std::transform::Footprint;
18+
use graphene_std::vector::Vector;
1819
use graphene_std::vector::click_target::ClickTarget;
1920
use graphene_std::vector::style::RenderMode;
2021

@@ -209,6 +210,9 @@ pub enum DocumentMessage {
209210
UpdateClipTargets {
210211
clip_targets: HashSet<NodeId>,
211212
},
213+
UpdateVectorData {
214+
vector_data: HashMap<NodeId, Arc<Vector>>,
215+
},
212216
Undo,
213217
UngroupSelectedLayers,
214218
UngroupLayer {

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,20 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
14241424
DocumentMessage::UpdateClipTargets { clip_targets } => {
14251425
self.network_interface.update_clip_targets(clip_targets);
14261426
}
1427+
DocumentMessage::UpdateVectorData { vector_data } => {
1428+
// Convert NodeId keys to LayerNodeIdentifier keys, filtering to only layers
1429+
let layer_vector_data = vector_data
1430+
.into_iter()
1431+
.filter(|(node_id, _)| self.network_interface.document_network().nodes.contains_key(node_id))
1432+
.filter_map(|(node_id, vector)| {
1433+
self.network_interface.is_layer(&node_id, &[]).then(|| {
1434+
let layer = LayerNodeIdentifier::new(node_id, &self.network_interface);
1435+
(layer, vector)
1436+
})
1437+
})
1438+
.collect();
1439+
self.network_interface.update_vector_data(layer_vector_data);
1440+
}
14271441
DocumentMessage::Undo => {
14281442
if self.network_interface.transaction_status() != TransactionStatus::Finished {
14291443
return;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pub struct DocumentMetadata {
3030
pub click_targets: HashMap<LayerNodeIdentifier, Vec<Arc<ClickTarget>>>,
3131
pub clip_targets: HashSet<NodeId>,
3232
pub vector_modify: HashMap<NodeId, Vector>,
33+
/// Vector data keyed by layer ID, used as fallback when no Path node exists.
34+
/// This provides accurate SegmentIds for layers without explicit Path nodes.
35+
pub layer_vector_data: HashMap<LayerNodeIdentifier, Arc<Vector>>,
3336
/// Transform from document space to viewport space.
3437
pub document_to_viewport: DAffine2,
3538
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,11 +3076,7 @@ impl NodeNetworkInterface {
30763076
return Some(modified);
30773077
}
30783078

3079-
self.document_metadata
3080-
.click_targets
3081-
.get(&layer)
3082-
.map(|click| click.iter().map(|x| x.target_type()))
3083-
.map(|target_types| Vector::from_target_types(target_types, true))
3079+
self.document_metadata.layer_vector_data.get(&layer).map(|arc| arc.as_ref().clone())
30843080
}
30853081

30863082
/// Loads the structure of layer nodes from a node graph.
@@ -3194,6 +3190,11 @@ impl NodeNetworkInterface {
31943190
pub fn update_vector_modify(&mut self, new_vector_modify: HashMap<NodeId, Vector>) {
31953191
self.document_metadata.vector_modify = new_vector_modify;
31963192
}
3193+
3194+
/// Update the layer vector data (for layers without Path nodes)
3195+
pub fn update_vector_data(&mut self, new_layer_vector_data: HashMap<LayerNodeIdentifier, Arc<Vector>>) {
3196+
self.document_metadata.layer_vector_data = new_layer_vector_data;
3197+
}
31973198
}
31983199

31993200
// Public mutable methods

editor/src/node_graph_executor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ impl NodeGraphExecutor {
412412
first_element_source_id,
413413
click_targets,
414414
clip_targets,
415+
vector_data,
415416
} = render_output.metadata;
416417

417418
// Run these update state messages immediately
@@ -422,6 +423,7 @@ impl NodeGraphExecutor {
422423
});
423424
responses.add(DocumentMessage::UpdateClickTargets { click_targets });
424425
responses.add(DocumentMessage::UpdateClipTargets { clip_targets });
426+
responses.add(DocumentMessage::UpdateVectorData { vector_data });
425427
responses.add(DocumentMessage::RenderScrollbars);
426428
responses.add(DocumentMessage::RenderRulers);
427429
responses.add(OverlaysMessage::Draw);

node-graph/libraries/rendering/src/renderer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ pub struct RenderMetadata {
249249
pub first_element_source_id: HashMap<NodeId, Option<NodeId>>,
250250
pub click_targets: HashMap<NodeId, Vec<Arc<ClickTarget>>>,
251251
pub clip_targets: HashSet<NodeId>,
252+
pub vector_data: HashMap<NodeId, Arc<Vector>>,
252253
}
253254

254255
impl RenderMetadata {
@@ -1187,6 +1188,8 @@ impl Render for Table<Vector> {
11871188
.collect::<Vec<_>>();
11881189

11891190
metadata.click_targets.entry(element_id).or_insert(click_targets);
1191+
// Store the full vector data including segment IDs for accurate segment modification
1192+
metadata.vector_data.entry(element_id).or_insert_with(|| Arc::new(vector.clone()));
11901193
}
11911194

11921195
if let Some(upstream_nested_layers) = &vector.upstream_data {

0 commit comments

Comments
 (0)