Skip to content

Commit c2d62fb

Browse files
committed
timetravel: make revert work with git
1 parent 1413dee commit c2d62fb

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,21 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
386386
};
387387

388388
// Revert the live version of the document to a specific version */
389-
revert = async (version: Date): Promise<void> => {
390-
if (this.syncdoc == null) return;
391-
this.syncdoc.revert(version);
392-
this.syncdoc.commit();
389+
revert = async (id: string, version: Date, doc: Document): Promise<void> => {
390+
const { syncdoc } = this;
391+
if (syncdoc == null) {
392+
return;
393+
}
394+
const node = this.getFrameNodeGlobal(id);
395+
syncdoc.commit();
396+
if (node.get("git_mode")) {
397+
syncdoc.from_str(doc.to_str());
398+
} else {
399+
syncdoc.revert(version);
400+
}
401+
await syncdoc.commit();
393402
await this.open_file();
394-
if (this.syncdoc == null) return;
395-
this.syncdoc.emit("change");
403+
syncdoc.emit("change");
396404
};
397405

398406
open_snapshots = (): void => {

src/packages/frontend/frame-editors/time-travel-editor/revert-file.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@ import { TimeTravelActions } from "./actions";
88
import { Icon } from "../../components";
99

1010
interface Props {
11+
id: string;
1112
actions: TimeTravelActions;
1213
version: Date | undefined;
14+
doc;
1315
}
1416

15-
export function RevertFile(props: Props) {
17+
export function RevertFile({ id, actions, version, doc }: Props) {
1618
return (
1719
<Button
1820
title={`Revert file to the displayed version (this makes a new version, so nothing is lost)`}
1921
onClick={() => {
20-
if (props.version != null) {
21-
props.actions.revert(props.version);
22+
if (version != null) {
23+
actions.revert(id, version, doc);
2224
}
2325
}}
24-
disabled={props.version == null || props.actions.syncdoc?.is_read_only()}
26+
disabled={version == null || actions.syncdoc?.is_read_only()}
2527
>
2628
<Icon name="undo" /> Revert
2729
</Button>

src/packages/frontend/frame-editors/time-travel-editor/time-travel.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,17 @@ export function TimeTravel(props: Props) {
272272
};
273273

274274
const renderRevertFile = () => {
275-
if (changesMode) {
275+
if (changesMode || doc == null) {
276276
return;
277277
}
278-
return <RevertFile actions={props.actions} version={getVersion()} />;
278+
return (
279+
<RevertFile
280+
actions={props.actions}
281+
version={getVersion()}
282+
id={props.id}
283+
doc={doc}
284+
/>
285+
);
279286
};
280287

281288
const renderChangesMode = () => {

0 commit comments

Comments
 (0)