Repository navigation
Conversation
👷 Deploy request for react-arborist pending review.Visit the deploys page to approve it
|
3db5f93 to
ac83c6e
Compare
|
Thanks for the review. All points have been addressed in commit
|
|
Opened #402 to address the Backspace multi-selection focus fallback on trailing nodes. |
The keyboard handler now dispatches through one table keyed by KeyboardEvent.key, so each command is a small function and the cyclomatic complexity of the entry point is four instead of twenty-nine. The type-to-find buffer moved from module scope into a WeakMap keyed by tree, so two trees no longer type into one shared search term. Behaviour is otherwise unchanged, including PageDown no longer leaking into type-to-find.
Address review feedback on keyboard handling: - Route 'a' and 'A' to typeahead when tree.props.onCreate is not set so read-only trees do not swallow character keys. - Filter out non-character keys and modifier shortcuts before typeahead, and compare lowercase search terms. - Standardize key handlers to (e, tree), removing inline lambdas and redundant Array.from copy. - Add test verifying 'a' falls through to type-to-find without onCreate, and verify non-character keys do not corrupt search. - Strengthen Backspace test to assert deleted IDs and resulting focused node.
…election deletion When multiple nodes at the end of the tree are selected and deleted via Backspace, the focus fallback logic checked tree.lastNode without verifying whether it was also part of the selection. This caused focus to land on a node that was immediately deleted. When later siblings are unavailable or selected, findUnselectedFallback now finds the nearest unselected node preceding or following the selection. Also prevents single-node deletion from focusing the invisible root node when deleting the last root-level node. This folds jameskerr#402 into jameskerr#399.
d91ea1d to
5093b32
Compare
|
Folded #402 into this PR in commit
|
45448c8 to
47fe36d
Compare
TrevorBurnham
left a comment
There was a problem hiding this comment.
Thanks for this! Most of the comments below are about the new multi-select Backspace focus logic. The main problem is that focus can still land on a node that is about to be deleted, because it is the child of a selected folder.
A selected folder takes its descendants with it, so the focus fallback could land on a row that the same Backspace removes. Replace the sibling walk plus visible-index scan with one visible-order search that skips any row under a selected node, and fall back to the focused row when the most recent selection is inside a collapsed folder. Drop the Math.max(...indices) spread so Ctrl+A then Backspace on a very large tree cannot overflow the call stack. Keep AltGr and macOS Option-composed characters in type-to-find; only real modifier shortcuts are ignored now. Rewrite the changeset to lead with what users will notice.
Synthetic dragover events never put the pointer in a folder row's middle band, so that spec has been failing on main. Dropping just above the folder's first row still moves the expense inside and exercises the same folder totals, without depending on the synthetic pointer position.
`Math.min(...nodes.map(...))` passes one argument per selected node, so select-all then Backspace on a 100k-row tree threw a RangeError before onDelete ran. Track the minimum in a loop instead.
TrevorBurnham
left a comment
There was a problem hiding this comment.
Thanks for this, the key-handler table is much easier to follow than the old switch. I checked that the merged computeDrop branches are byte-identical and that the per-tree typeahead works (the tree object comes from useMemo in the provider). The component tests pass warning-clean on this branch.
I found one real bug in the multi-select Backspace focus (when the selection is hidden inside a collapsed folder), and a couple of behaviour questions. The rest are small cleanups. Details are inline.
|
All nine threads are answered and resolved in
Verified locally: 12 suites / 155 tests, warning-clean; |
Summary
Keyboard handling in
DefaultContainerwas one ~190-lineonKeyDownhandler: a chain of per-key guard blocks inside a single function, so a change to one command meant editing the same function and each command could only be tested through the whole chain.computeDropalso carried two identical branches for the node above the cursor.This moves each command into its own function in
components/handle-tree-key-down.ts, dispatches them from one table, and merges the twocomputeDropbranches. It also fixes the pre-existing bugs in keyboard handling, including the multi-selection Backspace focus fallback from #402 which is now folded here.Closes #397. Folds and closes #402. Independent of the
@dnd-kitmigration in #391; it was split out of that stack because it does not depend on it.Merge order
create-root ↔ node-apicycle and adds the madge CI guard; rebase onto it before merging here so the new step runs green.compute-drop.tsandtree-api.tsregions; landing this first leaves only trivial hunks for the dnd-kit rewrite.What changed
components/handle-tree-key-down.ts(new): one function per command (Backspace, ArrowUp/Down/Left/Right, Home, End, PageUp/PageDown, Enter, Ctrl/Cmd+A, typeahead, Tab), each with an early return when it does not apply, plus aKEY_HANDLERStable keyed byKeyboardEvent.key. An unlisted character key falls through to type-to-find, non-character keys and modifier shortcuts are ignored, anda/Afall through to type-to-find whenonCreateis unset. The entry point's cyclomatic complexity drops from 29 to 4.components/default-container.tsx:onKeyDownnow callshandleTreeKeyDown; the component keeps only its element wiring.dnd/compute-drop.ts: the item-above and closed-folder-above branches become one condition. Same result, one place to change.interfaces/tree-api.ts:delete()tracks the first affected row index in a loop instead ofMath.min(...nodes.map(...)), which passed one argument per selected node.components/default-container.test.tsx: coverage for the branches the restructure touches, listed under Tests below.Bugs fixed on the way
PageUpandPageDownin an if-chain, and thePageDownbranch had noreturn, so it fell through into the type-to-find code below and appended the literal stringPageDownto the search term. Keys are now either handled or passed to type-to-find, never both.TreeApias privatetypeaheadTerm/typeaheadTimeoutwith aclearTypeahead()method, which the provider calls next tocancelHover()on unmount, so the pending timeout is cleared too.Shift,Alt,Escape, or shortcuts likeCtrl+Cused to append the key name or letter to the typeahead buffer. They are now filtered out before reaching typeahead, while AltGr (Ctrl+Alt) and macOS Option-composed letters still search.Math.min(...selectedIndices)overflowed the call stack on a very large selection.nextFocusAfterDeleteis now one visible-order scan: forward from the most recent row (or the focused row when the selection is hidden), then backward, skipping any row that has a selected ancestor.TreeApi.delete()had the same spread on the same path and now uses areduce.AwithoutonCreatedid nothing. It now runs type-to-find, like any other character.my fkeeps searching) instead of selecting. Once the 600ms window lapses it goes back to select/activate/toggle.preventDefault()now runs before thedisableMultiSelectionearly return, so the browser's select-all never fires.getModifierState("AltGraph")) and macOS Option-composed characters still search, but a bare Alt+letter on Windows/Linux (Alt+D focuses the address bar) no longer does.Testing
yarn workspace react-arborist test: 12 suites, 155 tests passing, no console warnings. Thirteen new tests, including PageDown not leaking into type-to-find, per-tree typeahead, Ctrl+A versusa,awithoutonCreate, non-character keys and modifiers, AltGr and Option-composed letters, Backspace focus after deleting a nested selection (children, siblings, collapsed folder), and the single-node root fallback.yarn build-lib,yarn lint,yarn fmt:check: clean.yarn workspace showcase build+xvfb-run yarn workspace e2e test: 5 specs, 22 tests passing.madge --circular: 1 cycle, the onemainhas; rebase onto Untangle the one circular import and the patterns that add more #400 before merging, since that PR adds the guard to CI.Budget demo e2e
budget-spechad been failing onmainitself: the helper fireddragoverwith no pointer, so Cypress sent clientX/clientY 0 andmeasureHoverresolved the cursor above the row, never in a folder row's middle band. The helper now sendsdragenter(react-dnd needs it to register the drop target) and passes explicit client coordinates at the middle of the target row, so the drop nests throughcomputeDrop'snode.isInternal && hover.inMiddlebranch - the case the comment describes. Verified locally: library and showcase rebuilt,budget-spec.cy.js2/2 passing.