Skip to content

Commit

Permalink
Clean up control flow
Browse files Browse the repository at this point in the history
  • Loading branch information
0HyperCube committed Dec 16, 2024
1 parent a63fe80 commit 6c38f72
Showing 1 changed file with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1586,41 +1586,26 @@ impl NodeNetworkInterface {
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 last_selection_state = network_metadata.persistent_metadata.selection_undo_history.back().cloned().unwrap_or_default();
let is_selection_empty = last_selection_state.selected_layers_except_artboards(self).next().is_none();

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.push_back(last_selection_state);
network_metadata.persistent_metadata.selection_redo_history.clear();
if !is_selection_empty {
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();
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");
Expand Down

0 comments on commit 6c38f72

Please sign in to comment.