Support rearranging layers with hotkeys (#271)

* Support moving single layers

* Fix "Move layer to top/bottom" keybinds

* Rename things named "move" to "reorder"

Fix formatting

* Combine sorted layer helper functions

* Use integer consts for moving layers to front/back

* Fix merge mistake

* Fix some clippy lints

* Fix panic

* Remove "get" prefix from functions

* Bring layer menu items out to sub-menu

* Support moving multiple layers at a time

* Add comment explaining odd keybinding

* Add reordering tests

* Add negative test

* Add new error type

* Add layer position helper, clean up tests

* Make position helper return Result

* Clean up slice iteration

* Simplify source_layer_ids computation

Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
AJ Weeks
2021-07-21 11:36:51 +02:00
committed by GitHub
co-authored by Dennis Kobert
parent 255cdead28
commit a448b36d9e
10 changed files with 319 additions and 13 deletions
@@ -126,6 +126,17 @@ const menuEntries: MenuListEntries = [
[
{ label: "Select All", shortcut: ["Ctrl", "A"], action: async () => (await wasm).select_all_layers() },
{ label: "Deselect All", shortcut: ["Ctrl", "Alt", "A"], action: async () => (await wasm).deselect_all_layers() },
{
label: "Order",
children: [
[
{ label: "Raise To Front", shortcut: ["Ctrl", "Shift", "]"], action: async () => (await wasm).reorder_selected_layers(2147483647) },
{ label: "Raise", shortcut: ["Ctrl", "]"], action: async () => (await wasm).reorder_selected_layers(1) },
{ label: "Lower", shortcut: ["Ctrl", "["], action: async () => (await wasm).reorder_selected_layers(-1) },
{ label: "Lower to Back", shortcut: ["Ctrl", "Shift", "["], action: async () => (await wasm).reorder_selected_layers(-2147483648) },
],
],
},
],
],
},
+9 -1
View File
@@ -176,7 +176,7 @@ pub fn select_all_layers() -> Result<(), JsValue> {
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::SelectAllLayers)).map_err(convert_error)
}
/// Select all layers
/// Deselect all layers
#[wasm_bindgen]
pub fn deselect_all_layers() -> Result<(), JsValue> {
EDITOR_STATE
@@ -184,6 +184,14 @@ pub fn deselect_all_layers() -> Result<(), JsValue> {
.map_err(convert_error)
}
/// Reorder selected layer
#[wasm_bindgen]
pub fn reorder_selected_layers(delta: i32) -> Result<(), JsValue> {
EDITOR_STATE
.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::ReorderSelectedLayers(delta)))
.map_err(convert_error)
}
/// Export the document
#[wasm_bindgen]
pub fn export_document() -> Result<(), JsValue> {
+4
View File
@@ -131,6 +131,10 @@ pub fn translate_key(name: &str) -> Key {
"arrowdown" => KeyArrowDown,
"arrowleft" => KeyArrowLeft,
"arrowright" => KeyArrowRight,
"[" => KeyLeftBracket,
"]" => KeyRightBracket,
"{" => KeyLeftCurlyBracket,
"}" => KeyRightCurlyBracket,
_ => UnknownKey,
}
}