fix(dashboard): make Escape revert a keyboard move that displaced a neighbour - #349
Merged
Merged
Conversation
…eighbour Cancelling a keyboard move announced success while the screen kept the new layout. Cancel restored the grabbed widget only, so gravity floated it straight back into the hole the displaced neighbour had left, and the neighbour was never put back at all. Nothing was corrupted — localStorage still held the pre-pickup layout and a reload repaired the view — but the announcement and the screen disagreed. PR #303 declined to snapshot the layout on the grounds that gridstack compaction is reversible. It is not, once a move displaces something: a single pickup and one arrow key is enough. Snapshot the whole layout at pick-up and restore it in one batch on cancel, via a new restoreLayout on the composable. The snapshot is built from positionOf/sizeOf rather than copied off the layout map: a widget that has not been resized yet carries no size there, and a snapshot missing it would restore the position while leaving the new size in place. grabbedOrigin and grabbedOriginSize are gone — the snapshot replaces both. The two Escape tests asserted the restoring call rather than the state it produced, so they now assert the layout.
|
📦 Preview published for commit Install the preview with dist-tag: npm install @vc-shell/framework@pr-349Or pin to the exact commit: npm install @vc-shell/framework@2.5.0-pr349.7d2b0d2Published packages (dist-tag
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Cancelling a keyboard move with
Escapeannounced "Move cancelled. Offers returned to its original position and size." while the screen kept the new layout. Cancel restored the grabbed widget only, so gravity floated it straight back into the hole the displaced neighbour had left — and the neighbour was never put back at all.Not data loss:
localStoragestill held the pre-pickup layout, so a reload repaired the view. The defect is that the announcement and the screen disagreed.Why it was not caught
PR #303 declined to snapshot the layout, on the grounds that gridstack compaction is reversible — "moving a widget back pulls the others with it". That holds until a move displaces something, and then one pickup plus one arrow key is enough to break it. The parent ticket's Escape check happened to use a horizontal move plus a resize, which does revert cleanly.
Fix
Snapshot the whole layout at pick-up; restore it in one batch on cancel, through a new
restoreLayouton theuseGridstackcomposable.The snapshot is built from
positionOf/sizeOfrather than copied off the layout map. A widget that has not been resized yet carries no size in that map, and a snapshot missing it would restore the position while leaving the new size in place — the first version of this change had exactly that bug, and an existing test caught it.grabbedOriginandgrabbedOriginSizeare deleted; the snapshot replaces both.Tests
Escape→ both widgets are back. Reverting to the single-widget restore fails it and nothing else.restoreLayouton the composable: writes every entry and batches the grid update; and copies the snapshot rather than adopting it, since the caller holds it across the restore.updateWidgetPosition/updateWidgetSizecalls rather than the state produced, so the new path broke them without any behaviour changing. They now assert the layout — which is also what this file's own comment says went wrong in VCST-5600.The neighbour's displacement is gridstack's doing and reaches the component through
layout, so the test writes it there the way the change handler does.Verification
vue-tscclean ·vitest run4108 passed, exit 0 ·lint:checkclean · prettier, stylelint, madge and layer checks clean.Committed with
--no-verify: the pre-commit hook lints only the staged files, and that narrow invocation reports a falseimport/no-unresolvedthe fulllint:checkdoes not.Closes VCST-5804