Drag to rearrange layers in the layer panel (#434)

* Add insert line

* Implement dragging

* Improve CSS and variable naming consistency

* Resolved folder crash, added Undo/Redo support

* Removed marker TODO leftover

* JS cleanup

* WIP preserving expanded state (via LayerData) when copy/pasting and moving layers in layer panel

* Finish making folders copy/paste preserving expanded state, but not recursively yet

* Add cut, copy, and paste to the Edit menu (#440)

* Add cut

* Hook up edit dropdown

* Use copy message

Co-authored-by: Keavon Chambers <keavon@keavon.com>
Co-authored-by: otdavies <oliver@psyfer.io>
This commit is contained in:
0HyperCube
2021-12-30 09:18:18 -08:00
committed by GitHub
co-authored by Keavon Chambers otdavies
parent 62fc88264e
commit cc560cb83b
9 changed files with 264 additions and 36 deletions
+15 -9
View File
@@ -490,11 +490,16 @@ impl Document {
responses.extend(update_thumbnails_upstream(folder));
Some(responses)
}
Operation::PasteLayer { path, layer, insert_index } => {
let folder = self.folder_mut(path)?;
let id = folder.add_layer(layer.clone(), None, *insert_index).ok_or(DocumentError::IndexOutOfBounds)?;
let full_path = [path.clone(), vec![id]].concat();
self.mark_as_dirty(&full_path)?;
Operation::InsertLayer {
destination_path,
layer,
insert_index,
} => {
let (folder_path, layer_id) = split_path(destination_path)?;
let folder = self.folder_mut(folder_path)?;
folder.add_layer(layer.clone(), Some(layer_id), *insert_index).ok_or(DocumentError::IndexOutOfBounds)?;
self.mark_as_dirty(destination_path)?;
fn aggregate_insertions(folder: &Folder, path: &mut Vec<LayerId>, responses: &mut Vec<DocumentResponse>) {
for (id, layer) in folder.layer_ids.iter().zip(folder.layers()) {
path.push(*id);
@@ -505,13 +510,14 @@ impl Document {
path.pop();
}
}
let mut responses = Vec::new();
if let Ok(folder) = self.folder(&full_path) {
aggregate_insertions(folder, &mut full_path.clone(), &mut responses)
if let Ok(folder) = self.folder(destination_path) {
aggregate_insertions(folder, &mut destination_path.clone(), &mut responses)
};
responses.extend([DocumentChanged, CreatedLayer { path: full_path }, FolderChanged { path: path.clone() }]);
responses.extend(update_thumbnails_upstream(path));
responses.extend([DocumentChanged, CreatedLayer { path: destination_path.clone() }, FolderChanged { path: folder_path.to_vec() }]);
responses.extend(update_thumbnails_upstream(destination_path));
Some(responses)
}
Operation::DuplicateLayer { path } => {
+2 -2
View File
@@ -76,9 +76,9 @@ pub enum Operation {
path: Vec<LayerId>,
name: String,
},
PasteLayer {
InsertLayer {
layer: Layer,
path: Vec<LayerId>,
destination_path: Vec<LayerId>,
insert_index: isize,
},
CreateFolder {