mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 23:47:33 +00:00
fix(studio): Escape keeps the text you typed in an in-place edit (#4841)
This commit is contained in:
@@ -345,7 +345,7 @@ describe("useInlineTextEdit", () => {
|
||||
act(() => root.unmount());
|
||||
});
|
||||
|
||||
it("cancels on Escape", () => {
|
||||
it("commits on Escape", () => {
|
||||
const element = heading("Original");
|
||||
const { controls, root, onCommit } = mount();
|
||||
act(() => {
|
||||
@@ -355,8 +355,38 @@ describe("useInlineTextEdit", () => {
|
||||
element.textContent = "half-typed";
|
||||
press(element, "Escape");
|
||||
|
||||
expect(element.textContent).toBe("Original");
|
||||
expect(onCommit).not.toHaveBeenCalled();
|
||||
expect(element.textContent).toBe("half-typed");
|
||||
expect(onCommit).toHaveBeenCalledTimes(1);
|
||||
expect(controls().session).toBeNull();
|
||||
act(() => root.unmount());
|
||||
});
|
||||
|
||||
// The save carries the styled markup it replaced, which is what undo puts back.
|
||||
it("saves typing ended by Escape once, with the markup it replaced", async () => {
|
||||
const element = heading();
|
||||
element.innerHTML = 'Hello <span style="color: red">world</span>';
|
||||
const { controls, root, onCommit } = mount();
|
||||
act(() => {
|
||||
controls().start(element);
|
||||
});
|
||||
await act(async () => {
|
||||
await new Promise((resolve) => requestAnimationFrame(() => resolve(null)));
|
||||
});
|
||||
expect(document.activeElement).toBe(element);
|
||||
|
||||
element.innerHTML = 'Hello <span style="color: red">world</span>!';
|
||||
press(element, "Escape");
|
||||
|
||||
expect(onCommit.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
element,
|
||||
html: 'Hello <span style="color: red">world</span>!',
|
||||
previousHtml: 'Hello <span style="color: red">world</span>',
|
||||
},
|
||||
],
|
||||
]);
|
||||
expect(element.innerHTML).toBe('Hello <span style="color: red">world</span>!');
|
||||
act(() => root.unmount());
|
||||
});
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ export function useInlineTextEdit({
|
||||
}
|
||||
if (event.key === "Escape") {
|
||||
event.preventDefault();
|
||||
cancel();
|
||||
commit();
|
||||
}
|
||||
};
|
||||
// Clicking away keeps the work, which is what every other field in Studio
|
||||
@@ -243,7 +243,7 @@ export function useInlineTextEdit({
|
||||
element.removeEventListener("dragover", onDragOver);
|
||||
element.removeEventListener("drop", onDrop);
|
||||
};
|
||||
}, [session, commit, cancel]);
|
||||
}, [session, commit]);
|
||||
|
||||
// Unmount keeps the typed words, as blur does. Read through a ref so a new
|
||||
// onCommit never closes the session mid-edit.
|
||||
|
||||
Reference in New Issue
Block a user