@@ -21,6 +21,7 @@ Elm.debuggerAttach = function(module, hotSwapState /* =undefined */) {
2121};
2222
2323var EVENTS_PER_SAVE = 100;
24+var eventCounter = 0;
2425
2526function dispatchElmDebuggerInit() {
2627 if (parent.window) {
@@ -81,8 +82,8 @@ function debugModule(module, runtime) {
8182 return false;
8283 }
8384 else {
84− var changed = runtime.notify(id, v, timestep);
8585 recordEvent(id, v, timestep);
86+ var changed = runtime.notify(id, v, timestep);
8687 if (eventsUntilSnapshot === 1) {
8788 saveSnapshot();
8889 eventsUntilSnapshot = EVENTS_PER_SAVE;
@@ -115,6 +116,7 @@ function debugModule(module, runtime) {
115116 function recordEvent(id, v, timestep) {
116117 watchTracker.pushFrame();
117118 recordedEvents.push({ id:id, value:v, timestep:timestep });
119+ eventCounter += 1;
118120 }
119121
120122 function clearAsyncCallbacks() {
@@ -127,6 +129,7 @@ function debugModule(module, runtime) {
127129
128130 function clearRecordedEvents() {
129131 recordedEvents = [];
132+ eventCounter = 0;
130133 }
131134
132135 function getRecordedEventsLength() {
@@ -177,6 +180,8 @@ function debugModule(module, runtime) {
177180 eventsUntilSnapshot = EVENTS_PER_SAVE - (position % EVENTS_PER_SAVE);
178181 snapshots = snapshots.slice(0, lastSnapshotPosition);
179182 recordedEvents = recordedEvents.slice(0, position);
183+ tracePath.clearTracesAfter(position);
184+ eventCounter = position;
180185 executeCallbacks(asyncCallbacks, false);
181186 }
182187 tracePath.startRecording();
@@ -216,7 +221,6 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
216221 var closestSnapshot = debugModule.getSnapshotAt(position);
217222 debugModule.clearAsyncCallbacks();
218223 restoreSnapshot(debugModule.signalGraphNodes, closestSnapshot);
219− // clear traces here.
220224 redrawGraphics();
221225 }
222226
@@ -314,11 +318,14 @@ function debuggerInit(debugModule, runtime, hotSwapState /* =undefined */) {
314318 debugModule.loadRecordedEvents(hotSwapState.recordedEvents);
315319 var index = getMaxSteps();
316320 var eventsUntilSnapshot = EVENTS_PER_SAVE;
321+ eventCounter = 0;
322+ debugModule.tracePath.clearTraces();
317323
318324 // draw new trace path
319325 debugModule.tracePath.startRecording();
320326 while(currentEventIndex < index) {
321327 var nextEvent = debugModule.getRecordedEventAt(currentEventIndex);
328+ eventCounter += 1;
322329 runtime.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
323330 if (eventsUntilSnapshot === 1) {
324331 debugModule.saveSnapshot();
@@ -403,14 +410,19 @@ function tracePathInit(runtime, signalGraphMain) {
403410 for (var id in positions) {
404411 var pos = positions[id];
405412 if (tracePositions.hasOwnProperty(id)) {
406− var points = tracePositions[id];
407− if (!pos.equals(points[points.length-1])) {
408− points.push(pos);
409− }
413+ tracePositions[id].push(pos);
410414 }
411415 else {
412416 tracePositions[id] = [pos];
413417 }
418+ if (tracePositions[id].length < eventCounter) {
419+ var padCount = eventCounter - tracePositions[id].length;
420+ var lastTracePosition = tracePositions[id][tracePositions[id].length - 1];
421+ for (var i = padCount; i--;) {
422+ tracePositions[id].push(lastTracePosition)
423+ }
424+ }
425+ assert(tracePositions[id].length === eventCounter, "We don't have a 1-1 mapping of trace positions to events")
414426 }
415427 }
416428
@@ -468,10 +480,19 @@ function tracePathInit(runtime, signalGraphMain) {
468480 recordingTraces = true;
469481 }
470482
483+ function clearTracesAfter(position) {
484+ var newTraces = {};
485+ for (var id in tracePositions) {
486+ newTraces[id] = tracePositions[id].slice(0,position);
487+ }
488+ tracePositions = newTraces;
489+ }
490+
471491 return {
472492 graphicsUpdate: graphicsUpdate,
473493 canvas: tracePathCanvas,
474494 clearTraces: clearTraces,
495+ clearTracesAfter: clearTracesAfter,
475496 stopRecording: stopRecording,
476497 startRecording: startRecording
477498 }