Restore rig highlight by id, paired with autosave

The previous fix derived the highlight by full-state equality against library
entries, which broke as soon as the working rig was edited — e.g. after
learning a MIDI binding, the working midiMap no longer equalled the saved
entry, so nothing was highlighted on restart.

Revert to an id-based highlight (survives edits, since edits don't change which
saved rig the session derives from) and additionally persist the current-rig id
on every autosave, so the stored id can never drift from the autosaved graph —
which was the original cause of the highlight/graph mismatch.

Both app targets build; suite green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 14:03:22 -07:00
parent 48ac573489
commit dee1c29744
@@ -699,6 +699,9 @@ public struct ShoeGazeBuilderView: View {
/// survives a restart even without an explicit Save; the app shells also save on background. /// survives a restart even without an explicit Save; the app shells also save on background.
private func autosave() { private func autosave() {
RigStore.save(shoeGaze) RigStore.save(shoeGaze)
// Pair the current-rig id with every graph write so the persisted highlight can never drift
// from the autosaved graph (the source of the highlight/graph mismatch on restart).
persistCurrentRigID()
} }
/// Removes every board, then seeds one fresh empty board so the builder is never boardless. /// Removes every board, then seeds one fresh empty board so the builder is never boardless.
@@ -874,21 +877,21 @@ public struct ShoeGazeBuilderView: View {
// MARK: - Rig library // MARK: - Rig library
/// Highlights the library entry that matches the restored working rig, once the library has /// Highlights the rig the working session derives from, once the library has loaded. Runs once.
/// loaded. Runs once.
/// ///
/// The working graph is restored from the autosave file independently of any persisted /// The current rig id is written paired with every autosave (see ``autosave()``), so the stored
/// selection, so the highlight is derived from the *actual* loaded graph rather than a separate /// id always tracks the loaded graph — including after edits such as learning a MIDI binding,
/// stored id (which could point at a different rig and mislabel what's shown). If the working /// which change the graph but not which saved rig it came from. Only highlights when nothing is
/// graph is an unsaved/edited session that matches no saved entry, nothing is highlighted. /// selected yet and the saved id still exists in the library.
private func restoreCurrentRig() { private func restoreCurrentRig() {
guard !didRestoreRig, library.isLoaded else { return } guard !didRestoreRig, library.isLoaded else { return }
didRestoreRig = true didRestoreRig = true
guard currentRigID == nil else { return } guard currentRigID == nil,
let working: ShoeGazeState = shoeGaze.captureState() let stored: String = UserDefaults.standard.string(
if let match: RigEntry = library.entries.first(where: { $0.state == working }) { forKey: ShoeGazeBuilderView.currentRigDefaultsKey),
currentRigID = match.id let id: UUID = UUID(uuidString: stored),
} library.entries.contains(where: { $0.id == id }) else { return }
currentRigID = id
} }
/// Persists `currentRigID` so the same rig is highlighted on the next launch. /// Persists `currentRigID` so the same rig is highlighted on the next launch.