fix(studio): the sheet's keys leave a key to the control that took it, and the layers tree works by keyboard

The sheet listened on the window in the capture phase, before any control saw
a key. Delete on a focused gradient stop removed the whole shape, an arrow on
the angle dial or the radial centre also moved the shape, and Delete, the
arrows and Ctrl+V pressed on a button of the assistant's window acted on the
page although the window stops its keys. The sheet now listens on the
document as the key bubbles, after every control had it and still before the
page's Escape on the window, and leaves a key whose default was prevented. A
gradient stop takes Delete and Backspace even when the last two stops cannot
go.

The layers panel was a tree a keyboard could not walk: only its toggles could
be focused. The tree is now one stop in the Tab order, the row last focused or
else the selected one. Up and Down move along the rows, Home and End to the
ends, Right opens a group or steps into it and Left closes it or steps from a
member up to its group (mirrored right to left), Enter or Space selects a row
as a click does with Shift adding, and F2 renames it. Enter and Escape in the
name field hand the focus back to its row, and the row in focus is ringed. A
hidden or locked layer that cannot be clicked on the page is reached this way.
This commit is contained in:
Maurice
2026-10-24 04:06:37 +00:00
parent 84e18e4954
commit 117af4a8a7
8 changed files with 320 additions and 15 deletions
+12 -6
View File
@@ -9,8 +9,12 @@ import { useStudioStore } from '../../store/studioStore';
* Every shortcut here is one a design tool has taught people already, and none
* of them takes a key away from the browser while somebody is typing: in a
* field, a text area or a text being edited on the page, the keys are the
* field's. Undo and redo are the Studio page's own (useJourneyStudio.ts), and
* every action below is one undo step there.
* field's. Nor from a control that takes the key itself: a gradient stop,
* the angle dial or a row of the layers tree prevents its default, and the
* assistant's window stops its keys from reaching the page, so Delete on a
* focused stop removes the stop, not the shape. Undo and redo are the Studio
* page's own (useJourneyStudio.ts), and every action below is one undo step
* there.
*
* - Delete or Backspace: remove what is selected and not locked.
* - Ctrl+C, Ctrl+V: copy and paste elements, onto any page (#2316).
@@ -134,7 +138,7 @@ export function useStudioKeys(opts: { spreadIndex: number; editing: boolean }) {
};
const onKey = (e: KeyboardEvent) => {
if (editing || isTypingTarget(e.target)) return;
if (editing || e.defaultPrevented || isTypingTarget(e.target)) return;
const store = useStudioStore.getState();
// Read when the key comes, not when the effect ran: a nudge changes the
// page, and an effect that re-ran on it would close the gesture each step.
@@ -164,13 +168,15 @@ export function useStudioKeys(opts: { spreadIndex: number; editing: boolean }) {
if (ARROWS[e.key]) stopNudge();
};
// Capture, so a step out of a group is decided before the page's Escape clears the selection.
window.addEventListener('keydown', onKey, true);
// On the document as the key bubbles: after every control and the assistant's window had it (React
// listens below the document), and before the page's Escape on the window, so a step out of a group
// is decided before the page clears the selection.
document.addEventListener('keydown', onKey);
window.addEventListener('keyup', onKeyUp, true);
window.addEventListener('blur', stopNudge);
return () => {
stopNudge();
window.removeEventListener('keydown', onKey, true);
document.removeEventListener('keydown', onKey);
window.removeEventListener('keyup', onKeyUp, true);
window.removeEventListener('blur', stopNudge);
};