M1.3 Wire smart insert into map click, preserve undo/redo #12

Closed
opened 2026-07-27 11:04:00 +00:00 by jmz · 2 comments
Owner

Replace append-on-click with the smart index from M1.2, reusing the existing splice/changeset/undo path. Start/finish clicks still extend ends. Manual + e2e verification.

Replace append-on-click with the smart index from M1.2, reusing the existing splice/changeset/undo path. Start/finish clicks still extend ends. Manual + e2e verification.
Author
Owner

Wiring plan (from the code read).

Map-click currently appends: calculateRouteBetween(last, click) → insertIntoRoute(push). Change to compute k = chooseInsertionIndex(anchors, click) (see #11), then:

  • k === n → append (unchanged)
  • k === 0 → prepend: route click→anchors[0], insertIntoRoute(wp, 0). ⚠️ insertIntoRoute has an if(index) falsy-0 bug (valhalla_store.svelte.ts:116) — index 0 falls through to push; must fix/special-case.
  • 0 < k < n → split the gap: editRoute(k-1, route(anchors[k-1]→click)) + insertIntoRoute(route(click→anchors[k]), k) (mirrors the line-drag path) + insert the anchor marker at k.

All paths already push changesets → undo/redo preserved. Also update the anchor-marker array + numbering.

**Wiring plan (from the code read).** Map-click currently appends: `calculateRouteBetween(last, click) → insertIntoRoute(push)`. Change to compute `k = chooseInsertionIndex(anchors, click)` (see #11), then: - `k === n` → append (unchanged) - `k === 0` → prepend: route `click→anchors[0]`, `insertIntoRoute(wp, 0)`. ⚠️ **`insertIntoRoute` has an `if(index)` falsy-0 bug** (`valhalla_store.svelte.ts:116`) — index 0 falls through to `push`; must fix/special-case. - `0 < k < n` → split the gap: `editRoute(k-1, route(anchors[k-1]→click))` + `insertIntoRoute(route(click→anchors[k]), k)` (mirrors the line-drag path) + insert the anchor marker at k. All paths already push changesets → undo/redo preserved. Also update the anchor-marker array + numbering.
Author
Owner

✅ Done — commit f0ea569e on feat/smart-insertion.

  • Added addAnchorSmart(lat, lon) in the route editor: computes k = chooseInsertionIndex(anchors, {lat,lon}); k===N keeps the existing append path, 0<k<N splits the segment between anchors[k-1] and anchors[k] and re-routes both halves (mirrors handleSegmentDragEnd), k===0 prepends a new start.
  • Repointed the map-click handler (drawing mode) from addAnchorAndRecalculate → addAnchorSmart.
  • Fixed the insertIntoRoute index-0 bug (valhalla_store.svelte.ts): if (index) → if (index !== undefined) (0 was falsy → appended). No existing caller passes 0; prepend relies on it.
  • Undo/redo preserved (all paths go through the changeset stack).

Verify: svelte-check clean (0 errors / 0 warnings, 2437 files); route_insertion unit tests 11/11 green. Browser/e2e validation pending a deploy (M0.2) or local npm run dev.

✅ **Done** — commit `f0ea569e` on `feat/smart-insertion`. - Added `addAnchorSmart(lat, lon)` in the route editor: computes `k = chooseInsertionIndex(anchors, {lat,lon})`; `k===N` keeps the existing append path, `0<k<N` splits the segment between `anchors[k-1]` and `anchors[k]` and re-routes both halves (mirrors `handleSegmentDragEnd`), `k===0` prepends a new start. - Repointed the map-click handler (drawing mode) from `addAnchorAndRecalculate` → `addAnchorSmart`. - Fixed the **`insertIntoRoute` index-0 bug** (`valhalla_store.svelte.ts`): `if (index)` → `if (index !== undefined)` (0 was falsy → appended). No existing caller passes 0; prepend relies on it. - Undo/redo preserved (all paths go through the changeset stack). **Verify:** `svelte-check` clean (0 errors / 0 warnings, 2437 files); `route_insertion` unit tests 11/11 green. Browser/e2e validation pending a deploy (M0.2) or local `npm run dev`.
jmz closed this issue 2026-07-27 13:08:56 +00:00
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer#12
No description provided.