Skip to content

Commit 2973c46

Browse files
committed
timetravel: set to newest version when toggling mode
1 parent ae7b1b9 commit 2973c46

File tree

1 file changed

+19
-3
lines changed
  • src/packages/frontend/frame-editors/time-travel-editor

1 file changed

+19
-3
lines changed

src/packages/frontend/frame-editors/time-travel-editor/actions.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,31 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
348348
}
349349
};
350350

351-
setGitMode = (id: string, git_mode: boolean): void => {
351+
setGitMode = async (id: string, git_mode: boolean) => {
352352
for (const actions of [this, this.ambient_actions]) {
353353
if (actions == null) continue;
354354
const node = actions._get_frame_node(id);
355355
if (node == null) continue;
356+
const cur = !!node.get("git_mode");
356357
git_mode = !!git_mode;
357-
actions.set_frame_tree({ id, git_mode });
358+
if (cur != git_mode) {
359+
// actually changing it
360+
actions.set_frame_tree({ id, git_mode });
361+
let versions;
362+
if (git_mode) {
363+
// also set version to newest on change to git mode
364+
versions =
365+
this.store.get("git_versions") ?? (await this.updateGitVersions());
366+
} else {
367+
// set version to newest on change from git mode to time travel
368+
versions = this.store.get("versions");
369+
}
370+
if (versions != null) {
371+
actions.set_frame_tree({ id, version: versions.size - 1 });
372+
}
373+
}
358374
break;
359375
}
360-
this.updateGitVersions();
361376
};
362377

363378
setVersions = (id: string, version0: number, version1: number): void => {
@@ -482,6 +497,7 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
482497
git_versions,
483498
});
484499
this.ensureSelectedVersionsAreConsistent({ git_versions });
500+
return git_versions;
485501
} catch (err) {
486502
this.set_error(`${err}`);
487503
this.setState({ git: false });

0 commit comments

Comments
 (0)