From a63fe8045ac73f031cb362c4951bca3baedce74a Mon Sep 17 00:00:00 2001 From: 0SlowPoke0 Date: Sat, 14 Dec 2024 09:38:17 +0530 Subject: [PATCH] removed the fsm code --- .../utility_types/network_interface.rs | 26 ++++++++++++++++--- .../tool/tool_messages/select_tool.rs | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/editor/src/messages/portfolio/document/utility_types/network_interface.rs b/editor/src/messages/portfolio/document/utility_types/network_interface.rs index b75eaa2b02..31e0847676 100644 --- a/editor/src/messages/portfolio/document/utility_types/network_interface.rs +++ b/editor/src/messages/portfolio/document/utility_types/network_interface.rs @@ -1585,22 +1585,42 @@ impl NodeNetworkInterface { /// Mutably get the selected nodes for the network at the network_path. Every time they are mutated, the transient metadata for the top of the stack gets unloaded. pub fn selected_nodes_mut(&mut self, network_path: &[NodeId]) -> Option<&mut SelectedNodes> { self.unload_stack_dependents(network_path); + + let last_selection_state = { + let Some(network_metadata) = self.network_metadata_mut(network_path) else { + log::error!("Could not get nested network_metadata in selected_nodes"); + return None; + }; + + network_metadata.persistent_metadata.selection_undo_history.back().cloned().unwrap_or_default() + }; + + let layers_except_artboards: Vec<_> = last_selection_state.selected_layers_except_artboards(self).collect(); + + // If the selection is empty or contains only artboards, skip the undo history update. + if layers_except_artboards.is_empty() { + let Some(network_metadata) = self.network_metadata_mut(network_path) else { + log::error!("Could not get nested network_metadata in selected_nodes"); + return None; + }; + + return network_metadata.persistent_metadata.selection_undo_history.back_mut(); + } + let Some(network_metadata) = self.network_metadata_mut(network_path) else { log::error!("Could not get nested network_metadata in selected_nodes"); return None; }; - let last_selection_state = network_metadata.persistent_metadata.selection_undo_history.back().cloned().unwrap_or_default(); - network_metadata.persistent_metadata.selection_undo_history.push_back(last_selection_state); network_metadata.persistent_metadata.selection_redo_history.clear(); if network_metadata.persistent_metadata.selection_undo_history.len() > crate::consts::MAX_UNDO_HISTORY_LEN { network_metadata.persistent_metadata.selection_undo_history.pop_front(); } + network_metadata.persistent_metadata.selection_undo_history.back_mut() } - pub fn selection_step_back(&mut self, network_path: &[NodeId]) { let Some(network_metadata) = self.network_metadata_mut(network_path) else { log::error!("Could not get nested network_metadata in selection_step_back"); diff --git a/editor/src/messages/tool/tool_messages/select_tool.rs b/editor/src/messages/tool/tool_messages/select_tool.rs index 91d22fc804..c17f31bced 100644 --- a/editor/src/messages/tool/tool_messages/select_tool.rs +++ b/editor/src/messages/tool/tool_messages/select_tool.rs @@ -1011,7 +1011,7 @@ impl Fsm for SelectToolFsmState { let new_selected: HashSet<_> = document.intersect_quad_no_artboards(quad, input).collect(); let current_selected: HashSet<_> = document.network_interface.selected_nodes(&[]).unwrap().selected_layers(document.metadata()).collect(); - if new_selected != current_selected && !new_selected.is_empty() { + if new_selected != current_selected { tool_data.layers_dragging = new_selected.into_iter().collect(); responses.add(NodeGraphMessage::SelectedNodesSet { nodes: tool_data