Skip to content

Floors: reorder from the editor + repair hand-edited ids — closes #66#69

Open
nicosandller wants to merge 1 commit into
mainfrom
fix/floor-reorder
Open

Floors: reorder from the editor + repair hand-edited ids — closes #66#69
nicosandller wants to merge 1 commit into
mainfrom
fix/floor-reorder

Conversation

@nicosandller

Copy link
Copy Markdown
Owner

Issue #66 is two complaints in one — "editing the order of floors in YAML causes configuration errors" and "let me reorder floors without YAML". This PR does both.

The feature: ▲/▼ in the floor gear

The floor gear popover gains an Order row: move the active floor up/down the list. Position in the list is what the editor dropdown and the card's floor switcher display, so the reporter's roof-stuck-in-the-basement is two clicks from the top. Buttons disable at the ends, the move commits through history (a mis-move is one Ctrl+Z away), and the logic is a pure, unit-tested moveFloor().

The bug: what hand-reordering actually breaks

Reordering floor blocks in YAML is cut-and-paste, and cut-and-paste routinely drops or duplicates the id: line. Reproduced both in the harness against main:

  • Duplicated id (pasted a block twice): every editor commit patches both floors sharing the id — drawing a wall on "Roof" also draws it on "Basement", silently. This is the truly nasty one.
  • Missing id: every by-id lookup misses — floor switching dies in the editor and the card.

getFloors now repairs both at the normalization boundary: missing ids backfill deterministically by position (floor_1, floor_2, …), collisions keep the first occurrence and suffix the rest. Deterministic-by-position means the repair is stable across renders (lookups don't churn) and persists into the YAML on the next editor commit.

Also fixed while here: the floor <select> bound ?selected — the default-selection attribute — so after a reorder the browser's index-based live selection could point at the wrong floor. It now binds the .selected property.

Verification

  • tsc clean, 211/211 tests (206 on main + 5: id repair incl. stability and name/id pairing, moveFloor moves/ends/unknown-id/immutability).
  • Harness, the reporter's scenario end-to-end: Basement/Ground/Roof with Roof active → ▲ twice → Roof, Basement, Ground, ▲ now disabled at the top, ▼ was disabled at the bottom; Ctrl+Z ×2 restores the original order; the card's floor switcher renders in the new order. Duplicate-id config before/after: an edit used to land on both floors (One:1 | Two:1), now on exactly the edited one (One:0 | Two:1).

Backwards compatibility

Well-formed configs pass through byte-identical (same ids, same order). Only configs that were already broken (missing/colliding ids) change — they get working ids, which is the repair. No schema additions.

Closes #66.

🤖 Generated with Claude Code

Feature: the floor gear popover gains an Order row — move the active
floor up/down the list (disabled at the ends, undoable). List position is
the dropdown and floor-switcher order, so a roof stuck in the basement is
two clicks from the top.

Bug half: reordering floors by cut-and-paste in YAML routinely drops or
duplicates floor ids. Reproduced the damage: a duplicated id makes every
commit patch BOTH floors (edits silently land on the wrong floor); a
missing id kills floor switching. getFloors now repairs both — missing
ids backfill deterministically by position (floor_N), collisions get a
positional suffix, first occurrence keeps its id — so the repair is
stable across renders and persists on the next editor commit.

Also: the floor <select> binds .selected (live property) instead of
?selected (default-only attribute), so a reorder can't strand the
browser's index-based selection on the wrong floor.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Editing the order of floors

1 participant