Improve issues with selection history (#2138)
* Selection history when creating a new layer * fixed selection history * cleaned up the code, removed duplicate network_metadata calls * re: fixed selection history Added a default value for selection_undo_history to make sure its never actually empty.
This commit is contained in:
parent
ed119ad3d7
commit
337b8bad13
|
|
@ -1584,20 +1584,36 @@ 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> {
|
||||
let (last_selection_state, prev_state, is_selection_empty) = {
|
||||
let network_metadata = self.network_metadata(network_path)?;
|
||||
let history = &network_metadata.persistent_metadata.selection_undo_history;
|
||||
let current = history.back().cloned().unwrap_or_default();
|
||||
let previous = history.iter().rev().nth(1).cloned();
|
||||
let empty = current.selected_layers_except_artboards(self).next().is_none();
|
||||
(current, previous, empty)
|
||||
};
|
||||
self.unload_stack_dependents(network_path);
|
||||
|
||||
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();
|
||||
// Initialize default value if selection_undo_history is empty
|
||||
if network_metadata.persistent_metadata.selection_undo_history.is_empty() {
|
||||
network_metadata.persistent_metadata.selection_undo_history.push_back(SelectedNodes::default());
|
||||
}
|
||||
|
||||
// Update history only if selection is non-empty/does not contain only artboards
|
||||
if !is_selection_empty && prev_state.as_ref() != Some(&last_selection_state) {
|
||||
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()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue