Public: anyone can read this; the crew can change it.

small: Escape leaves the tell box and keeps its draft per page #16774

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15031-small-escape-leaves-the-tell-box-and-kee → main 0 commits fork

  • Merged. scout/15031-small-escape-leaves-the-tell-box-and-kee was merged into main as 24468de.

Review

Sign in to review this change.
4 files changed +37 −1
src/web/draft.ts +6
@@ -38,6 +38,12 @@ function forgeDraft(storage, box, key, later) {
3838 var mine = round;
3939 later(function () { if (mine === round) save(); }, DELAY);
4040 },
41 // Leaving the box (Escape, a click away): save now, so a reload inside the delay keeps the words.
42 leave: function () {
43 if (!pending) return;
44 round++;
45 save();
46 },
4147 // A refused send: give the words back unless new ones have been typed.
4248 refused: function (text) {
4349 if (!box.value) box.value = text;
src/web/studio/feed.ts +1
@@ -792,6 +792,7 @@ ${returnTargetJs}
792792 draft = forgeDraft(window.localStorage, draftBox, 'draft.' + draftBox.dataset.draft + location.pathname, function (fn, ms) { setTimeout(fn, ms); });
793793 draft.restore();
794794 draftBox.addEventListener('input', draft.typed);
795 draftBox.addEventListener('blur', draft.leave);
795796 forgeSendKey(draftBox, composer);
796797 }
797798 // An empty feed offers the box: the cursor goes in only where there is a keyboard and a
test/composer-draft.test.ts +13
@@ -232,3 +232,16 @@ test("a tell sent from the feed's composer comes back to the feed, the forge's t
232232 expect(new URL(res.headers.get("location") ?? "", servers.url).pathname).toBe("/feed");
233233 }
234234 });
235
236 test("leaving the box saves a waiting draft at once, so Escape then reload keeps it", () => {
237 const { store, box, timers, draft } = rig();
238 box.value = "make the gate green"; draft.typed();
239 expect(store.getItem("draft.u1/")).toBeNull();
240 (draft as unknown as { leave(): void }).leave(); // Escape blurs the box
241 expect(store.getItem("draft.u1/")).toBe("make the gate green");
242 timers.shift()!(); // the old timer is spent: no second save
243 box.value = "";
244 (draft as unknown as { leave(): void }).leave(); // nothing typed since: leaving saves nothing
245 expect(store.getItem("draft.u1/")).toBe("make the gate green");
246 expect(feedJs).toContain("addEventListener('blur', draft.leave)");
247 });
test/tell-key.test.ts +17 −1
@@ -103,7 +103,7 @@ test("Escape keeps the draft per page in the browser's store; the next visit's t
103103 const make = (w: Window, path: string) =>
104104 new Function("storage", "box", "key", "later", `${draftJs}\nreturn forgeDraft(storage, box, key, later);`)(
105105 store, w.document.querySelector("textarea"), `draft.u1${path}`, later,
106 ) as { restore: () => void; typed: () => void };
106 ) as { restore: () => void; typed: () => void; leave: () => void };
107107 const box = first.w.document.querySelector("textarea") as unknown as { value: string };
108108 make(first.w, "/feed").restore();
109109 first.press("t");
@@ -124,6 +124,22 @@ test("Escape keeps the draft per page in the browser's store; the next visit's t
124124 expect((other.w.document.querySelector("textarea") as unknown as { value: string }).value).toBe("");
125125 });
126126
127 test("type, Escape at once, reload: the draft is back without waiting for the save timer", () => {
128 const first = page("/feed", FEED);
129 const store = first.w.localStorage;
130 const draft = new Function("storage", "box", "key", "later", `${draftJs}\nreturn forgeDraft(storage, box, key, later);`)(
131 store, first.w.document.querySelector("textarea"), "draft.u1/feed", () => {},
132 ) as { restore: () => void; typed: () => void; leave: () => void };
133 const box = first.w.document.querySelector("textarea") as unknown as { value: string; addEventListener: (n: string, f: () => void) => void };
134 box.addEventListener("input", draft.typed);
135 box.addEventListener("blur", draft.leave);
136 first.press("t");
137 box.value = "make the gate green";
138 draft.typed(); // the timer never fires
139 first.press("Escape", box);
140 expect(store.getItem("draft.u1/feed")).toBe("make the gate green");
141 });
142
127143 test("a page that owns t keeps it: the shell's row never fires", () => {
128144 const { w, press, active } = page("/next", `${FEED}<a href="#top" data-shortcut="t">Top</a>`);
129145 let clicked = 0;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs