mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-03 10:28:11 +08:00
Fix layers losing their names upon being grouped (#1637)
* no message
* no message
* no message
* Make layers reserve their names when grouped
* remove redundancy
* replace String::from("") with String::new()
* Fix test
* Restore unrequested line break changes
* Avoid unwraps
---------
Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
128f76af7e
commit
a1f2a2b256
@@ -364,6 +364,7 @@ mod test {
|
|||||||
nodes: HashMap::new(),
|
nodes: HashMap::new(),
|
||||||
parent: LayerNodeIdentifier::ROOT,
|
parent: LayerNodeIdentifier::ROOT,
|
||||||
insert_index: -1,
|
insert_index: -1,
|
||||||
|
alias: String::new(),
|
||||||
});
|
});
|
||||||
editor.handle_message(NodeGraphMessage::SelectedNodesSet { nodes: vec![FOLDER_ID] });
|
editor.handle_message(NodeGraphMessage::SelectedNodesSet { nodes: vec![FOLDER_ID] });
|
||||||
|
|
||||||
|
|||||||
@@ -370,6 +370,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
|
|||||||
nodes: HashMap::new(),
|
nodes: HashMap::new(),
|
||||||
parent,
|
parent,
|
||||||
insert_index: -1,
|
insert_index: -1,
|
||||||
|
alias: String::new(),
|
||||||
});
|
});
|
||||||
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
|
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
|
||||||
}
|
}
|
||||||
@@ -423,7 +424,13 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
|
|||||||
|
|
||||||
let id = NodeId(generate_uuid());
|
let id = NodeId(generate_uuid());
|
||||||
let insert_index = -1;
|
let insert_index = -1;
|
||||||
responses.add(GraphOperationMessage::NewCustomLayer { id, nodes, parent, insert_index });
|
responses.add(GraphOperationMessage::NewCustomLayer {
|
||||||
|
id,
|
||||||
|
nodes,
|
||||||
|
parent,
|
||||||
|
insert_index,
|
||||||
|
alias: String::new(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FlipSelectedLayers { flip_axis } => {
|
FlipSelectedLayers { flip_axis } => {
|
||||||
@@ -501,6 +508,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
|
|||||||
nodes: HashMap::new(),
|
nodes: HashMap::new(),
|
||||||
parent,
|
parent,
|
||||||
insert_index: calculated_insert_index.unwrap_or(-1),
|
insert_index: calculated_insert_index.unwrap_or(-1),
|
||||||
|
alias: String::new(),
|
||||||
});
|
});
|
||||||
responses.add(PortfolioMessage::PasteIntoFolder {
|
responses.add(PortfolioMessage::PasteIntoFolder {
|
||||||
clipboard: Clipboard::Internal,
|
clipboard: Clipboard::Internal,
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ pub enum GraphOperationMessage {
|
|||||||
nodes: HashMap<NodeId, DocumentNode>,
|
nodes: HashMap<NodeId, DocumentNode>,
|
||||||
parent: LayerNodeIdentifier,
|
parent: LayerNodeIdentifier,
|
||||||
insert_index: isize,
|
insert_index: isize,
|
||||||
|
alias: String,
|
||||||
},
|
},
|
||||||
NewVectorLayer {
|
NewVectorLayer {
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
|
|||||||
+11
-1
@@ -670,7 +670,13 @@ impl MessageHandler<GraphOperationMessage, GraphOperationHandlerData<'_>> for Gr
|
|||||||
modify_inputs.insert_image_data(image_frame, layer);
|
modify_inputs.insert_image_data(image_frame, layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GraphOperationMessage::NewCustomLayer { id, nodes, parent, insert_index } => {
|
GraphOperationMessage::NewCustomLayer {
|
||||||
|
id,
|
||||||
|
nodes,
|
||||||
|
parent,
|
||||||
|
insert_index,
|
||||||
|
alias,
|
||||||
|
} => {
|
||||||
trace!("Inserting new layer {id} as a child of {parent:?} at index {insert_index}");
|
trace!("Inserting new layer {id} as a child of {parent:?} at index {insert_index}");
|
||||||
|
|
||||||
let mut modify_inputs = ModifyInputsContext::new(document_network, document_metadata, node_graph, responses);
|
let mut modify_inputs = ModifyInputsContext::new(document_network, document_metadata, node_graph, responses);
|
||||||
@@ -678,6 +684,10 @@ impl MessageHandler<GraphOperationMessage, GraphOperationHandlerData<'_>> for Gr
|
|||||||
if let Some(layer) = modify_inputs.create_layer_with_insert_index(id, insert_index, parent) {
|
if let Some(layer) = modify_inputs.create_layer_with_insert_index(id, insert_index, parent) {
|
||||||
let new_ids: HashMap<_, _> = nodes.iter().map(|(&id, _)| (id, NodeId(generate_uuid()))).collect();
|
let new_ids: HashMap<_, _> = nodes.iter().map(|(&id, _)| (id, NodeId(generate_uuid()))).collect();
|
||||||
|
|
||||||
|
if let Some(node) = modify_inputs.document_network.nodes.get_mut(&id) {
|
||||||
|
node.alias = alias.clone();
|
||||||
|
}
|
||||||
|
|
||||||
let shift = nodes
|
let shift = nodes
|
||||||
.get(&NodeId(0))
|
.get(&NodeId(0))
|
||||||
.and_then(|node| {
|
.and_then(|node| {
|
||||||
|
|||||||
@@ -21,4 +21,5 @@ pub struct CopyBufferEntry {
|
|||||||
pub nodes: HashMap<NodeId, DocumentNode>,
|
pub nodes: HashMap<NodeId, DocumentNode>,
|
||||||
pub selected: bool,
|
pub selected: bool,
|
||||||
pub collapsed: bool,
|
pub collapsed: bool,
|
||||||
|
pub alias: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,6 +180,8 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
|||||||
};
|
};
|
||||||
|
|
||||||
let node = layer.to_node();
|
let node = layer.to_node();
|
||||||
|
let previous_alias = active_document.network().nodes.get(&node).map(|node| node.alias.clone()).unwrap_or_default();
|
||||||
|
|
||||||
let Some(node) = active_document.network().nodes.get(&node).and_then(|node| node.inputs.first()).and_then(|input| input.as_node()) else {
|
let Some(node) = active_document.network().nodes.get(&node).and_then(|node| node.inputs.first()).and_then(|input| input.as_node()) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
@@ -197,6 +199,7 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
|||||||
.collect(),
|
.collect(),
|
||||||
selected: active_document.selected_nodes.selected_layers_contains(layer, active_document.metadata()),
|
selected: active_document.selected_nodes.selected_layers_contains(layer, active_document.metadata()),
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
|
alias: previous_alias,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -375,6 +378,7 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
|||||||
nodes: entry.nodes.clone(),
|
nodes: entry.nodes.clone(),
|
||||||
parent,
|
parent,
|
||||||
insert_index,
|
insert_index,
|
||||||
|
alias: entry.alias.clone(),
|
||||||
});
|
});
|
||||||
if entry.selected {
|
if entry.selected {
|
||||||
responses.add(NodeGraphMessage::SelectedNodesAdd { nodes: vec![id] });
|
responses.add(NodeGraphMessage::SelectedNodesAdd { nodes: vec![id] });
|
||||||
@@ -408,6 +412,7 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
|||||||
nodes: entry.nodes,
|
nodes: entry.nodes,
|
||||||
parent,
|
parent,
|
||||||
insert_index: -1,
|
insert_index: -1,
|
||||||
|
alias: entry.alias,
|
||||||
});
|
});
|
||||||
if entry.selected {
|
if entry.selected {
|
||||||
responses.add(NodeGraphMessage::SelectedNodesAdd { nodes: vec![id] });
|
responses.add(NodeGraphMessage::SelectedNodesAdd { nodes: vec![id] });
|
||||||
|
|||||||
@@ -427,6 +427,7 @@ fn new_brush_layer(document: &DocumentMessageHandler, responses: &mut VecDeque<M
|
|||||||
nodes: HashMap::from([(NodeId(0), brush_node)]),
|
nodes: HashMap::from([(NodeId(0), brush_node)]),
|
||||||
parent: document.new_layer_parent(),
|
parent: document.new_layer_parent(),
|
||||||
insert_index: -1,
|
insert_index: -1,
|
||||||
|
alias: String::new(),
|
||||||
});
|
});
|
||||||
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
|
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
|
||||||
|
|
||||||
|
|||||||
@@ -341,7 +341,13 @@ impl SelectToolData {
|
|||||||
let id = NodeId(generate_uuid());
|
let id = NodeId(generate_uuid());
|
||||||
let insert_index = -1;
|
let insert_index = -1;
|
||||||
let layer = LayerNodeIdentifier::new_unchecked(id);
|
let layer = LayerNodeIdentifier::new_unchecked(id);
|
||||||
responses.add(GraphOperationMessage::NewCustomLayer { id, nodes, parent, insert_index });
|
responses.add(GraphOperationMessage::NewCustomLayer {
|
||||||
|
id,
|
||||||
|
nodes,
|
||||||
|
parent,
|
||||||
|
insert_index,
|
||||||
|
alias: String::new(),
|
||||||
|
});
|
||||||
new_dragging.push(layer);
|
new_dragging.push(layer);
|
||||||
}
|
}
|
||||||
let nodes = new_dragging.iter().map(|layer| layer.to_node()).collect();
|
let nodes = new_dragging.iter().map(|layer| layer.to_node()).collect();
|
||||||
|
|||||||
Reference in New Issue
Block a user