Renaming on touch: Cancel instead of an Esc hint, and an emptied title is a cancel
Fable on #179 (minor): "Return renames · Esc puts it back" was wrong on a phone, which has no Esc, and blur renamed, so there was no way back; and clearing the field then leaving it renamed the document to Untitled. - While the large title is being renamed a Cancel button shows; the hint about Return and Esc shows only where the pointer is fine (a keyboard). Cancel keeps focus in the field as it is pressed, so leaving the field does not rename first, and puts the title back. - A field left empty, by Return or by leaving it, puts the title back. New string (draft for copy review): docs.chrome.title.cancel "Cancel". TestThePhoneDocumentScreen checks the hint, Cancel and the emptied field without leaving the page; before this the emptied field renamed the document to Untitled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+65
−9
internal/docs/brand/phone.js+24 −6internal/docs/phone.go+2 −0internal/docs/phone_browser_test.go+25 −0internal/docs/render.go+4 −0internal/docs/views/show.html+10 −3
diff --git a/internal/docs/brand/phone.js b/internal/docs/brand/phone.js| index 5ed117c..7ac430b 100644 |
| --- a/internal/docs/brand/phone.js |
| +++ b/internal/docs/brand/phone.js |
| @@ -53,10 +53,21 @@ |
| var edit = form && form.querySelector("[docs-title-edit]"); |
| var startRename = function () {}; |
| if (form && input && edit) { |
| + var cancel = form.querySelector("[docs-title-cancel]"); |
| var stop = function (refocus) { |
| form.removeAttribute("data-editing"); |
| if (refocus) edit.focus(); |
| }; |
| + // Back to the title as it was. An emptied field is this too: a title |
| + // cleared and left is never meant as "Untitled" (Fable on #179). |
| + var putBack = function (refocus) { |
| + input.value = input.defaultValue; |
| + stop(refocus); |
| + }; |
| + var changed = function () { |
| + var v = input.value.trim(); |
| + return v !== "" && v !== input.defaultValue.trim(); |
| + }; |
| startRename = function () { |
| form.setAttribute("data-editing", ""); |
| input.focus(); |
| @@ -66,19 +77,26 @@ |
| input.addEventListener("keydown", function (e) { |
| if (e.key === "Enter") { |
| e.preventDefault(); |
| - if (input.value.trim() === input.defaultValue.trim()) stop(true); |
| - else form.requestSubmit(); |
| + if (changed()) form.requestSubmit(); |
| + else putBack(true); |
| } else if (e.key === "Escape") { |
| e.preventDefault(); |
| - input.value = input.defaultValue; |
| - stop(true); |
| + putBack(true); |
| } |
| }); |
| input.addEventListener("blur", function () { |
| if (!form.hasAttribute("data-editing")) return; |
| - if (input.value.trim() !== input.defaultValue.trim()) form.requestSubmit(); |
| - else stop(false); |
| + if (changed()) form.requestSubmit(); |
| + else putBack(false); |
| }); |
| + if (cancel) { |
| + // Pressing Cancel would take focus from the field first, and leaving |
| + // a changed field renames; so the press keeps focus in the field, |
| + // and the click puts the title back. |
| + cancel.addEventListener("pointerdown", function (e) { e.preventDefault(); }); |
| + cancel.addEventListener("mousedown", function (e) { e.preventDefault(); }); |
| + cancel.addEventListener("click", function () { putBack(true); }); |
| + } |
| } |
| // •••. |
diff --git a/internal/docs/phone.go b/internal/docs/phone.go| index fa0456e..9f64673 100644 |
| --- a/internal/docs/phone.go |
| +++ b/internal/docs/phone.go |
| @@ -23,6 +23,7 @@ type largeTitleView struct { |
| TitleLabel string |
| TitleHint string |
| Rename string |
| + Cancel string |
| ViewOnly string |
| // Status is the save state under the title: estilo's savestatus in |
| // its "subtitle" placement, saying the quiet states too. The page |
| @@ -37,6 +38,7 @@ func newLargeTitleView(r *http.Request, shared string) largeTitleView { |
| TitleLabel: rastrillo.T(r, "docs.chrome.title.label"), |
| TitleHint: rastrillo.T(r, "docs.chrome.title.hint"), |
| Rename: rastrillo.T(r, "docs.chrome.title.rename"), |
| + Cancel: rastrillo.T(r, "docs.chrome.title.cancel"), |
| ViewOnly: rastrillo.T(r, "docs.show.viewonly"), |
| Status: savestatus.Data{ |
| State: "saved", |
diff --git a/internal/docs/phone_browser_test.go b/internal/docs/phone_browser_test.go| index 8f7af3e..2d99af2 100644 |
| --- a/internal/docs/phone_browser_test.go |
| +++ b/internal/docs/phone_browser_test.go |
| @@ -165,6 +165,31 @@ func TestThePhoneDocumentScreen(t *testing.T) { |
| t.Error("Esc left the title in its field") |
| } |
| + // On a touch screen there is no Esc: the hint about it is not shown, |
| + // and Cancel puts the title back. Clearing the field and leaving it is |
| + // a cancel too, never a rename to Untitled (Fable on #179). Neither |
| + // leaves the page. |
| + type renaming struct { |
| + Editing, Hint, Cancel, Stayed bool |
| + Value, Title string |
| + } |
| + state := `({ Editing: !!document.querySelector('[docs-title-form][data-editing]'), Hint: !!document.querySelector('[docs-title-hint]').getClientRects().length, Cancel: !!document.querySelector('[docs-title-cancel]').getClientRects().length, Stayed: window.__stayed === true, Value: document.querySelector('[docs-title-input]').value, Title: document.querySelector('[docs-title-text]').textContent })` |
| + var r renaming |
| + run("rename, on touch", chromedp.Evaluate[chromedp.Void](`window.__stayed = true`), chromedp.Click(chromedp.CSS(`[docs-title-edit]`)), settle, evalInto(&r, state)) |
| + if !r.Editing || r.Hint || !r.Cancel { |
| + t.Errorf("renaming on touch: editing %v, the Esc hint shown %v, Cancel shown %v", r.Editing, r.Hint, r.Cancel) |
| + } |
| + run("Cancel", chromedp.Evaluate[chromedp.Void](`document.querySelector('[docs-title-input]').value = 'Changed'; true`), chromedp.Click(chromedp.CSS(`[docs-title-cancel]`)), settle, evalInto(&r, state)) |
| + if r.Editing || r.Value != "Minutes" || !r.Stayed { |
| + t.Errorf("after Cancel: editing %v, the field %q, still the same page %v", r.Editing, r.Value, r.Stayed) |
| + } |
| + run("clear and leave", chromedp.Click(chromedp.CSS(`[docs-title-edit]`)), settle, |
| + chromedp.Evaluate[chromedp.Void](`document.querySelector('[docs-title-input]').value = ''; document.querySelector('[docs-title-input]').blur(); true`), |
| + chromedp.Sleep(800*time.Millisecond), evalInto(&r, state)) |
| + if r.Editing || r.Value != "Minutes" || r.Title != "Minutes" || !r.Stayed { |
| + t.Errorf("after clearing the field and leaving it: editing %v, the field %q, the title %q, still the same page %v; want it put back", r.Editing, r.Value, r.Title, r.Stayed) |
| + } |
| + |
| // Aa shows the strip. |
| run("Aa", chromedp.Click(chromedp.CSS(`[docs-aa]`)), settle) |
| if p = probe("Aa"); !p.Strip { |
diff --git a/internal/docs/render.go b/internal/docs/render.go| index 7614a38..058bcc2 100644 |
| --- a/internal/docs/render.go |
| +++ b/internal/docs/render.go |
| @@ -474,6 +474,10 @@ var Catalog = rastrillo.Catalog{ |
| "docs.editor.more": "More", |
| "docs.show.viewonly": "View only", |
| "docs.chrome.title.hint": "Return renames · Esc puts it back", |
| + // docs.chrome.title.cancel is the large title's Cancel while it is |
| + // being renamed on a touch screen, where there is no Esc. Draft for |
| + // copy review (2026-11-28). |
| + "docs.chrome.title.cancel": "Cancel", |
| // docs.editor.toolbar.* — the formatting bar (show.html's |
| // [docs-toolbar], driven by fixtures/toolbar.mjs). Every one of |
diff --git a/internal/docs/views/show.html b/internal/docs/views/show.html| index 6802b7d..ad98330 100644 |
| --- a/internal/docs/views/show.html |
| +++ b/internal/docs/views/show.html |
| @@ -1727,12 +1727,18 @@ |
| hint in its place. Without, the field and its Rename button. Decided |
| by the media feature, so the first paint is already the right one. */ |
| @media (scripting: enabled) { |
| - [docs-title-form] :is([docs-title-input], [docs-title-hint], [docs-title-submit]) { display: none; } |
| + [docs-title-form] :is([docs-title-input], [docs-title-hint], [docs-title-submit], [docs-title-cancel]) { display: none; } |
| [docs-title-form][data-editing] [docs-title] { display: none; } |
| - [docs-title-form][data-editing] :is([docs-title-input], [docs-title-hint]) { display: block; } |
| + [docs-title-form][data-editing] [docs-title-input] { display: block; } |
| + /* Return and Esc are a keyboard's; on a touch screen the keyboard's |
| + own Done renames, and Cancel puts the title back (Fable on #179). */ |
| + [docs-title-form][data-editing] [docs-title-cancel] { display: inline-flex; margin-block-end: var(--rst-sp-2); } |
| + @media (pointer: fine) { |
| + [docs-title-form][data-editing] [docs-title-hint] { display: block; } |
| + } |
| } |
| @media (scripting: none) { |
| - [docs-title-form] [docs-title] { display: none; } |
| + [docs-title-form] :is([docs-title], [docs-title-cancel]) { display: none; } |
| [docs-title-form] [docs-title-input] { outline: 0; border-block-end: 1px solid var(--rst-line); } |
| [docs-title-form] [docs-title-submit] { margin-block: var(--rst-sp-2); } |
| } |
| @@ -1862,6 +1868,7 @@ |
| <span id="docs-title-edit-says" hidden>{{.Large.Rename}}</span> |
| <input docs-title-input id="docs-title-input" name="title" value="{{.Title}}" maxlength="256" aria-label="{{.Large.TitleLabel}}" aria-describedby="docs-title-hint" autocomplete="off" spellcheck="false" dir="auto" enterkeyhint="done"> |
| <p docs-title-hint id="docs-title-hint">{{.Large.TitleHint}}</p> |
| +<button rst-btn="ghost" type="button" docs-title-cancel>{{.Large.Cancel}}</button> |
| <button rst-btn type="submit" docs-title-submit>{{.Large.Rename}}</button> |
| </form> |
| {{- else}} |