-
-
Notifications
You must be signed in to change notification settings - Fork 1k
add keyboard shortcuts for renaming layers #3641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,7 @@ | |
| addEventListener("pointermove", draggingPointerMove); | ||
| addEventListener("mousedown", draggingMouseDown); | ||
| addEventListener("keydown", draggingKeyDown); | ||
| addEventListener("keydown", handleLayerPanelKeyDown); | ||
|
|
||
| addEventListener("pointermove", clippingHover); | ||
| addEventListener("keydown", clippingKeyPress); | ||
|
|
@@ -123,6 +124,7 @@ | |
| removeEventListener("pointermove", draggingPointerMove); | ||
| removeEventListener("mousedown", draggingMouseDown); | ||
| removeEventListener("keydown", draggingKeyDown); | ||
| removeEventListener("keydown", handleLayerPanelKeyDown); | ||
|
|
||
| removeEventListener("pointermove", clippingHover); | ||
| removeEventListener("keydown", clippingKeyPress); | ||
|
|
@@ -490,6 +492,58 @@ | |
| } | ||
| } | ||
|
|
||
| function handleLayerPanelKeyDown(e: KeyboardEvent) { | ||
| // Only handle F2 if not currently editing a layer name | ||
| if (e.key === "F2" && !isAnyLayerBeingEdited()) { | ||
| // Find the first selected layer | ||
| const selectedLayer = layers.find((layer) => layer.entry.selected); | ||
| if (selectedLayer) { | ||
| e.preventDefault(); | ||
| onEditLayerName(selectedLayer); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function isAnyLayerBeingEdited(): boolean { | ||
| return layers.some((layer) => layer.editingName); | ||
| } | ||
|
|
||
| async function navigateToLayer(currentListing: LayerListingInfo, direction: "next" | "previous" | "up" | "down") { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there's any reason to have four instead of two directions, when each pair are just synonyms of each other. Just name them "Up" and "Down", with the first letter capitalized because these are the JS equivalent of Rust's enum variants which are also PascalCase. |
||
| // Save the current layer name | ||
| const inputElement = document.activeElement; | ||
| if (inputElement instanceof HTMLInputElement) { | ||
| const name = inputElement.value || ""; | ||
| editor.handle.setLayerName(currentListing.entry.id, name); | ||
| currentListing.entry.alias = name; | ||
| } | ||
|
|
||
| // Find current layer index | ||
| const currentIndex = layers.findIndex((layer) => layer.entry.id === currentListing.entry.id); | ||
| if (currentIndex === -1) return; | ||
|
|
||
| // Calculate target index based on direction | ||
| let targetIndex: number; | ||
| if (direction === "next" || direction === "down") { | ||
| targetIndex = currentIndex + 1; | ||
| if (targetIndex >= layers.length) return; // Don't wrap around at the end | ||
| } else { | ||
| // previous or up | ||
| targetIndex = currentIndex - 1; | ||
| if (targetIndex < 0) return; // Don't wrap around at the beginning | ||
| } | ||
|
Comment on lines
+525
to
+533
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move |
||
|
|
||
| const targetListing = layers[targetIndex]; | ||
| if (!targetListing) return; | ||
|
|
||
| // Exit edit mode on current layer | ||
| currentListing.editingName = false; | ||
| draggable = true; | ||
| layers = layers; | ||
|
|
||
| // Start edit mode on target layer | ||
| await onEditLayerName(targetListing); | ||
| } | ||
|
|
||
| function fileDragOver(e: DragEvent) { | ||
| if (!draggable || !e.dataTransfer || !e.dataTransfer.types.includes("Files")) return; | ||
|
|
||
|
|
@@ -655,8 +709,22 @@ | |
| placeholder={listing.entry.reference.data} | ||
| disabled={!listing.editingName} | ||
| on:blur={() => onEditLayerNameDeselect(listing)} | ||
| on:keydown={(e) => e.key === "Escape" && onEditLayerNameDeselect(listing)} | ||
| on:keydown={(e) => e.key === "Enter" && onEditLayerNameChange(listing, e)} | ||
| on:keydown={(e) => { | ||
| if (e.key === "Escape") { | ||
| onEditLayerNameDeselect(listing); | ||
| } else if (e.key === "Enter") { | ||
| onEditLayerNameChange(listing, e); | ||
| } else if (e.key === "Tab") { | ||
| e.preventDefault(); | ||
| navigateToLayer(listing, e.shiftKey ? "previous" : "next"); | ||
| } else if (e.key === "ArrowUp") { | ||
| e.preventDefault(); | ||
| navigateToLayer(listing, "up"); | ||
| } else if (e.key === "ArrowDown") { | ||
| e.preventDefault(); | ||
| navigateToLayer(listing, "down"); | ||
| } | ||
| }} | ||
| on:change={(e) => onEditLayerNameChange(listing, e)} | ||
| /> | ||
| </LayoutRow> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A one-liner function that's only used once is rather unnecessary compared to just calling that logic inline and describing what's going on in the comment above it.