Change layer duplication so the duplicate is placed above the original (#1124)
Previously, the duplicated layer would be placed at the top of the stack. It is now inserted one layer above the original. --------- Co-authored-by: Ollie Dolan <olliedolan10@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
4c9ef0fe6c
commit
b83f2c24f1
|
|
@ -718,7 +718,11 @@ impl Document {
|
|||
let layer = self.layer(&path)?.clone();
|
||||
let (folder_path, _) = split_path(path.as_slice()).unwrap_or((&[], 0));
|
||||
let folder = self.folder_mut(folder_path)?;
|
||||
if let Some(new_layer_id) = folder.add_layer(layer, None, -1) {
|
||||
|
||||
let selected_id = path.last().copied().unwrap_or_default();
|
||||
let insert_index = folder.layer_ids.iter().position(|&id| id == selected_id).unwrap_or(0) as isize + 1;
|
||||
|
||||
if let Some(new_layer_id) = folder.add_layer(layer, None, insert_index) {
|
||||
let new_path = [folder_path, &[new_layer_id]].concat();
|
||||
self.mark_as_dirty(folder_path)?;
|
||||
Some(
|
||||
|
|
|
|||
|
|
@ -70,11 +70,14 @@ impl FolderLayer {
|
|||
pub fn add_layer(&mut self, layer: Layer, id: Option<LayerId>, insert_index: isize) -> Option<LayerId> {
|
||||
let mut insert_index = insert_index as i128;
|
||||
|
||||
// Bounds check for the insert index
|
||||
if insert_index < 0 {
|
||||
insert_index = self.layers.len() as i128 + insert_index + 1;
|
||||
}
|
||||
if insert_index > self.layers.len() as i128 || insert_index < 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
if insert_index <= self.layers.len() as i128 && insert_index >= 0 {
|
||||
if let Some(id) = id {
|
||||
self.next_assignment_id = id;
|
||||
}
|
||||
|
|
@ -92,9 +95,6 @@ impl FolderLayer {
|
|||
}
|
||||
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove a layer with a given ID from the folder.
|
||||
|
|
|
|||
Loading…
Reference in New Issue