!7 !include #1006440 // Concepts static double maxSleepTime = 2; // compress pauses to this time (seconds) static Session session; static JTextArea ta; static int caretPos; // Reorder caret moves & edits p { loadConceptsFrom(#1006438); print("Sessions: " + collectField('id, list(Session))); session = latest(Session); if (session == null) { print("Editor has not been run yet"); ret; } L events = sortConceptsByID(findBackRefs(Event, session)); print("Using session " + session.id + " with " + n(events, "events")); ta = showText(""); S text = ""; long time = session.created; setFrameTitle(ta, "Replaying"); for (Event e : events) { print(sfu(e)); long sleepTime = min(toMS(maxSleepTime), e.created-time); time = e.created; sleep(sleepTime); if (e << EChange) { text = replayEdit(e/EChange, text); setText(ta, text); if (caretPos != 0 && setCaretIfPossible(ta, caretPos)) caretPos = 0; } else if (e << ECaret) { int pos = e/ECaret.pos; if (!setCaretIfPossible(ta, pos)) caretPos = pos; } else print("Ignoring unknown event type: " + e); } setFrameTitle(ta, "Replay Done"); }