route editor: shortest-path insert by default + one undo step per action #44
No reviewers
Labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
public/wanderer!44
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/dwim-insert"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Route editor point-adding, per Jörg's 2026-11-01 spec. Based on
deploy@584644d7(includes #43 BRouter sign-in gate,9b3bc183). Do not merge from a bot; Jörg merges in the UI. No image build / no homelab-flux change in this PR.chooseInsertionIndex, unchanged: added length, ties -> append, prepend, n=0/1 special-cased). Two modes: shortest-path (default) and append-only. The existing toggle switches them; Alt / ⌥ / ⌘-click does the other mode for that click only (default mode: modifier-click appends once; append-only mode: modifier-click inserts once). Shift (one-off off-road/track) still composes.i18n:
append-to-end,insert-at-nearest,insert-modifier-hintreplaced byappend-only-mode("Appending to end of route"),shortest-path-mode("Shortest-path insertion"),mode-modifier-hint("Hold Alt / ⌘ while clicking to use the other mode once."), in en, de, fr (the only locales that had the old keys).handleSegmentClick, and line-drag viahandleSegmentDragEnd).addAnchor+splitSegment=editRoute+insertIntoRoute= two undo entries, neither with anchor snapshots, so undo fell back to re-deriving anchors from the route geometry and dropped the wrong point. Only the toggle/modifier insert path was tagged (tagLastRouteUndo); drag, line-click, line-drag, list-delete and segment-mode flip were not.Fix:
recordUserAction(fn)invalhalla_store.svelte.tssnapshots anchors + undo depth, runs the whole action, then folds every undo entry it pushed into one entry (changesets concatenated in order; reverse in reverse order) carryinganchorsBefore/After; an action that only changes anchors (first point) becomes an anchor-only entry.tagLastRouteUndois removed. All mutation paths go through it: append, shortest-path insert/prepend, modifier click, first anchor, on-line click, on-line drag, marker drag (pre-drag snapshot taken at dragstart; markers are moved back on undo), anchor-list/marker delete, segment-mode flip, reset. Anchor snapshots are copies so a later drag cannot rewrite history. Not changed:moveAnchor(already single-entry + tagged), loop-generator accept (documented segment-by-segment), reverse.Loop trade-off (decision)
The chooser alone inserts a click near the start A next to A (the last point is far away). Resolved (Jörg-approved): in shortest-path mode a plain click within 20 screen px of the first anchor, on a route with >= 3 anchors, appends (closes the loop). Implemented at the click wiring with a pure
closesLoophelper (pixel projection viamap.project), sochooseInsertionIndexstays pure; the chooser test still pins the raw behaviour. Modifier-click, append-only and on-line clicks are unchanged.Judged the suggested rule "prefer append when the click is closer to the last point than to any interior segment": not adopted. (a) It does not touch the loop case at all, where the click is near the first point and far from the last. (b) For clicks near the last point the chooser already appends unless the click lies inside the C-D leg's own detour circle, where inserting is the shorter path by a few metres; forcing append there only lengthens the path and breaks the "most logical path" contract. The start-snap rule above is what addresses loops. Test
never adds more length than appending wouldcovers the optimality claim over a grid.Tests
route_insertion.test.ts: loop-closing case, click beside last point, optimality grid.valhalla_undo.test.ts(new): the reported bug (A, B, on-line C -> one undo gives A,B), a six-step mixed history (append, shortest insert, prepend, on-line) stepped back and forth in exact order, marker drag (old position restored), list delete, last-anchor removal and reset, redo cleared by new action.vitest runon those two files (17 pass). Full suite and svelte-check: Forgejo CI.Manual browser test (adapted to the new behaviour)
Watch: on Linux desktops Alt+click may be grabbed by the window manager (window move); the toggle covers that. On Windows, ⌘ is the Windows key.
🤖 Generated with Claude Code
WIP: route editor: shortest-path insert by default + one undo step per actionto route editor: shortest-path insert by default + one undo step per action