Fix property panel selection when layer is added or deleted through undo/redo action (#716)

* Fixed layer property panel visibility for a deleted layer through an undo action

* Fix visible layer in property panel using broadcast signal for undo and redo actions

* Changed redo variable name to "next_selected_paths"

* Code review nit picks

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Rahul 2022-07-09 17:43:05 -05:00 committed by Keavon Chambers
parent 05b93ae3f4
commit 5d1d93917d
1 changed files with 24 additions and 0 deletions

View File

@ -365,14 +365,26 @@ impl DocumentMessageHandler {
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents // Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
responses.push_back(PortfolioMessage::UpdateOpenDocumentsList.into()); responses.push_back(PortfolioMessage::UpdateOpenDocumentsList.into());
let selected_paths: Vec<Vec<LayerId>> = self.selected_layers().map(|path| path.to_vec()).collect();
match self.document_undo_history.pop() { match self.document_undo_history.pop() {
Some((document, layer_metadata)) => { Some((document, layer_metadata)) => {
// Update the currently displayed layer on the Properties panel if the selection changes after an undo action
// Also appropriately update the Properties panel if an undo action results in a layer being deleted
let prev_selected_paths: Vec<Vec<LayerId>> = layer_metadata.iter().filter_map(|(layer_id, metadata)| metadata.selected.then(|| layer_id.clone())).collect();
if prev_selected_paths != selected_paths {
responses.push_back(BroadcastSignal::SelectionChanged.into());
}
let document = std::mem::replace(&mut self.graphene_document, document); let document = std::mem::replace(&mut self.graphene_document, document);
let layer_metadata = std::mem::replace(&mut self.layer_metadata, layer_metadata); let layer_metadata = std::mem::replace(&mut self.layer_metadata, layer_metadata);
self.document_redo_history.push((document, layer_metadata)); self.document_redo_history.push((document, layer_metadata));
for layer in self.layer_metadata.keys() { for layer in self.layer_metadata.keys() {
responses.push_back(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() }.into()) responses.push_back(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() }.into())
} }
Ok(()) Ok(())
} }
None => Err(EditorError::NoTransactionInProgress), None => Err(EditorError::NoTransactionInProgress),
@ -383,14 +395,26 @@ impl DocumentMessageHandler {
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents // Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
responses.push_back(PortfolioMessage::UpdateOpenDocumentsList.into()); responses.push_back(PortfolioMessage::UpdateOpenDocumentsList.into());
let selected_paths: Vec<Vec<LayerId>> = self.selected_layers().map(|path| path.to_vec()).collect();
match self.document_redo_history.pop() { match self.document_redo_history.pop() {
Some((document, layer_metadata)) => { Some((document, layer_metadata)) => {
// Update currently displayed layer on property panel if selection changes after redo action
// Also appropriately update property panel if redo action results in a layer being added
let next_selected_paths: Vec<Vec<LayerId>> = layer_metadata.iter().filter_map(|(layer_id, metadata)| metadata.selected.then(|| layer_id.clone())).collect();
if next_selected_paths != selected_paths {
responses.push_back(BroadcastSignal::SelectionChanged.into());
}
let document = std::mem::replace(&mut self.graphene_document, document); let document = std::mem::replace(&mut self.graphene_document, document);
let layer_metadata = std::mem::replace(&mut self.layer_metadata, layer_metadata); let layer_metadata = std::mem::replace(&mut self.layer_metadata, layer_metadata);
self.document_undo_history.push((document, layer_metadata)); self.document_undo_history.push((document, layer_metadata));
for layer in self.layer_metadata.keys() { for layer in self.layer_metadata.keys() {
responses.push_back(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() }.into()) responses.push_back(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() }.into())
} }
Ok(()) Ok(())
} }
None => Err(EditorError::NoTransactionInProgress), None => Err(EditorError::NoTransactionInProgress),