From 5d1d93917d184956ed0c73827e76a7aa226f2f4d Mon Sep 17 00:00:00 2001 From: Rahul <67343291+RahulHi@users.noreply.github.com> Date: Sat, 9 Jul 2022 17:43:05 -0500 Subject: [PATCH] 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 --- .../src/document/document_message_handler.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/editor/src/document/document_message_handler.rs b/editor/src/document/document_message_handler.rs index 6503b6dd..16bff422 100644 --- a/editor/src/document/document_message_handler.rs +++ b/editor/src/document/document_message_handler.rs @@ -365,14 +365,26 @@ impl DocumentMessageHandler { // Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents responses.push_back(PortfolioMessage::UpdateOpenDocumentsList.into()); + let selected_paths: Vec> = self.selected_layers().map(|path| path.to_vec()).collect(); + match self.document_undo_history.pop() { 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> = 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 layer_metadata = std::mem::replace(&mut self.layer_metadata, layer_metadata); self.document_redo_history.push((document, layer_metadata)); + for layer in self.layer_metadata.keys() { responses.push_back(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() }.into()) } + Ok(()) } 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 responses.push_back(PortfolioMessage::UpdateOpenDocumentsList.into()); + let selected_paths: Vec> = self.selected_layers().map(|path| path.to_vec()).collect(); + match self.document_redo_history.pop() { 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> = 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 layer_metadata = std::mem::replace(&mut self.layer_metadata, layer_metadata); self.document_undo_history.push((document, layer_metadata)); + for layer in self.layer_metadata.keys() { responses.push_back(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() }.into()) } + Ok(()) } None => Err(EditorError::NoTransactionInProgress),