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:
Christopher Mendoza
2023-04-16 15:34:02 -07:00
committed by Keavon Chambers
co-authored by Ollie Dolan Keavon Chambers
parent 4c9ef0fe6c
commit b83f2c24f1
2 changed files with 26 additions and 22 deletions
+5 -1
View File
@@ -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(