Skip to content

Write HTML. Render video. Built for agents.

feat(studio): a host undo key paints a still-saving move back at once (#4894)

Miguel Ángelde13693179f5
diff --git a/packages/studio/src/index.ts b/packages/studio/src/index.ts
index da6e19ce2a..c6ee950fae 100644
--- a/packages/studio/src/index.ts
+++ b/packages/studio/src/index.ts
@@ -148,6 +148,7 @@ export type {
// A host's own waitForPendingDomEditSaves must also call this, or undo/redo
// can race a write still in flight (see useTrackPendingTimelineEdit.ts).
export { flushStudioPendingEdits } from "./utils/studioPendingEdits";
+export { revertNewestStudioPendingEdit } from "./utils/studioPendingEdits";
export type { StudioPendingEditsDrainResult } from "./utils/studioPendingEdits";
export type {
CanEditTimelineElement,
diff --git a/packages/studio/src/utils/studioPendingEdits.test.ts b/packages/studio/src/utils/studioPendingEdits.test.ts
index 08f26f0f79..d518294fb8 100644
--- a/packages/studio/src/utils/studioPendingEdits.test.ts
+++ b/packages/studio/src/utils/studioPendingEdits.test.ts
@@ -10,6 +10,7 @@ import {
trackedStudioEdit,
} from "./studioPendingEdits";
import { StudioFileConflictError } from "./studioSaveDiagnostics";
+import { revertNewestStudioPendingEdit as hostRevert } from "../index";
describe("studio pending edit flush", () => {
it("waits for mounted panels to persist pending local edits", async () => {
@@ -277,3 +278,20 @@ describe("a pending edit whose start throws", () => {
expect(hasStudioPendingEdits()).toBe(false);
});
});
+
+describe("the package's public revert", () => {
+ it("lets a host's own undo key paint a still-saving move back at once", async () => {
+ let left = "120px";
+ const edit = beginStudioPendingEdit(() => ((left = "0px"), () => void (left = "120px")));
+ try {
+ const putBack = hostRevert();
+ expect(left).toBe("0px");
+ expect(hostRevert()).toBeNull();
+ putBack?.();
+ expect(left).toBe("120px");
+ } finally {
+ edit.settle();
+ await flushStudioPendingEdits();
+ }
+ });
+});