@@ -22405,7 +22405,6 @@ var OptFrontendSharedSessions = (function (_super) {
2240522405 _this.isIdle = false;
2240622406 _this.peopleIveKickedOut = []; // #savage
2240722407 _this.fullCodeSnapshots = []; // a list of full snapshots of code taken at given times, with:
22408- // {ts: new Date().getTime(), cod: <full code snapshot, not diff!>}
2240922408 _this.curPeekSnapshotIndex = -1; // current index you're peeking at inside of fullCodeSnapshots, -1 if not peeking at anything
2241022409 _this.initTogetherJS();
2241122410 _this.pyInputAceEditor.getSession().on("change", function (e) {
@@ -23212,29 +23211,19 @@ var OptFrontendSharedSessions = (function (_super) {
2321223211 // don't do this too frequently or else things might blow up.
2321323212 OptFrontendSharedSessions.prototype.takeFullCodeSnapshot = function () {
2321423213 var _this = this;
23215- var curTs = new Date().getTime();
2321623214 var curCod = this.pyInputGetValue();
23217- if (this.fullCodeSnapshots.length > 0) {
23218- var curEntry;
23219- var lastEntry = this.fullCodeSnapshots[this.fullCodeSnapshots.length - 1];
23220- if (this.curPeekSnapshotIndex < 0 ||
23221- this.curPeekSnapshotIndex >= this.fullCodeSnapshots.length /* shouldn't ever happen, but fail soft */) {
23222- curEntry = lastEntry;
23223- }
23224- else {
23225- curEntry = this.fullCodeSnapshots[this.curPeekSnapshotIndex];
23226- }
23227- if ((curEntry.cod == curCod) ||
23228- (curEntry.cod == lastEntry)) {
23229- // curCod identical to last saved version or currently-peeking version
23230- // that we're viewing, so don't do anything. RETURN EARLY!!!
23231- // note that there's no point in appending if you're identical to the
23232- // last entry either since you can always go to it.
23233- return;
23215+ // brute-force search through all of this.fullCodeSnapshots for an
23216+ // exact duplicate ... if it exists, then don't snapshot it again.
23217+ // this is super crude/potentially-inefficient but is the most robust
23218+ // way to check for changes in light of weird TogetherJS happenings
23219+ for (var i = 0; i < this.fullCodeSnapshots.length; i++) {
23220+ var e = this.fullCodeSnapshots[i];
23221+ if (e == curCod) {
23222+ return; // RETURN EARLY if there's a duplicate match!!!
2323423223 }
2323523224 }
23236- this.fullCodeSnapshots.push({ ts: curTs, cod: curCod } );
23237- // console.log('takeFullCodeSnapshot', this.fullCodeSnapshots.length, 'idx:', this.curPeekSnapshotIndex);
23225+ this.fullCodeSnapshots.push(curCod);
23226+ console.log('takeFullCodeSnapshot', this.fullCodeSnapshots.length, 'idx:', this.curPeekSnapshotIndex);
2323823227 // only give the option to restore old versions if YOU started this session,
2323923228 // or else it's too confusing if everyone gets to restore as a free-for-all.
2324023229 // also wait until this.fullCodeSnapshots has more than 1 element.
@@ -23247,13 +23236,8 @@ var OptFrontendSharedSessions = (function (_super) {
2324723236 if (_this.curPeekSnapshotIndex == 0) {
2324823237 return;
2324923238 }
23239+ _this.takeFullCodeSnapshot(); // try to snapshot *first* before you change the code
2325023240 if (_this.curPeekSnapshotIndex < 0) {
23251- // this is super duper tricky, since if you're trying to go
23252- // backwards but haven't peeked yet, then we need to save your
23253- // CURRENT snapshot so that we can restore it later if you
23254- // want; otherwise going back in time clobbers everything up
23255- // to your current snapshot:
23256- _this.takeFullCodeSnapshot();
2325723241 _this.curPeekSnapshotIndex = _this.fullCodeSnapshots.length - 1;
2325823242 }
2325923243 _this.curPeekSnapshotIndex--;
@@ -23267,14 +23251,12 @@ var OptFrontendSharedSessions = (function (_super) {
2326723251 if (_this.curPeekSnapshotIndex < 0) {
2326823252 return; // meaningless if you're not peeking
2326923253 }
23254+ _this.takeFullCodeSnapshot(); // try to snapshot *first* before you change the code
2327023255 _this.curPeekSnapshotIndex++;
2327123256 _this.renderCodeSnapshot();
2327223257 exports.TogetherJS.send({ type: "snapshotPeek", btn: 'next', idx: _this.curPeekSnapshotIndex, tot: _this.fullCodeSnapshots.length });
2327323258 });
2327423259 }
23275- // SUPER SUBTLE SH*T -- if we're taking a new snapshot, bring us to the
23276- // "latest" version right now, which means that we're no longer peeking
23277- this.curPeekSnapshotIndex = -1;
2327823260 // update the display at the end if necessary
2327923261 this.renderCodeSnapshot();
2328023262 };
@@ -23296,10 +23278,10 @@ var OptFrontendSharedSessions = (function (_super) {
2329623278 var cod;
2329723279 // this shouldn't happen but fail-soft just in case
2329823280 if (this.curPeekSnapshotIndex >= this.fullCodeSnapshots.length) {
23299- cod = this.fullCodeSnapshots[this.fullCodeSnapshots.length - 1].cod ;
23281+ cod = this.fullCodeSnapshots[this.fullCodeSnapshots.length - 1];
2330023282 }
2330123283 else {
23302- cod = this.fullCodeSnapshots[this.curPeekSnapshotIndex].cod ;
23284+ cod = this.fullCodeSnapshots[this.curPeekSnapshotIndex];
2330323285 }
2330423286 if (curCod != cod) {
2330523287 this.pyInputSetValue(cod);
0 commit comments