oficina / docs Public

web: a tap in the document closes the Format sheet

Review 2 on #181. A tap in the document while the sheet was open raised
the keyboard over the sheet, kept the capsule away, left Aa expanded
and drew the kept selection over the live one. The editor's focusin now
closes the sheet first.

TestATapInTheDocumentClosesTheSheet failed before this (the sheet still
open, no capsule, Aa expanded).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 0f21f7fac43201b507da0c79ab5ed40ccb9b8e8f parent 5c72cd7
2 files changed, +34 −1
  • internal/docs/brand/phone.js +7 −1
  • internal/docs/phone_sheet_browser_test.go +27 −0
diff --git a/internal/docs/brand/phone.js b/internal/docs/brand/phone.js
index 0721de4..6250df1 100644
--- a/internal/docs/brand/phone.js
+++ b/internal/docs/brand/phone.js
@@ -327,7 +327,13 @@
vv.addEventListener("scroll", place);
}
if (editor) {
- editor.addEventListener("focusin", place);
+ // A tap in the document while the sheet is open is a return to
+ // writing: the sheet goes, so the keyboard and the capsule come up
+ // and the kept selection gives way to the live one.
+ editor.addEventListener("focusin", function () {
+ if (sheetOpen()) setSheet(false);
+ place();
+ });
editor.addEventListener("focusout", function () { setTimeout(place, 0); });
}
if (compact && compact.addEventListener) compact.addEventListener("change", place);
diff --git a/internal/docs/phone_sheet_browser_test.go b/internal/docs/phone_sheet_browser_test.go
index fb58bdb..291bd4b 100644
--- a/internal/docs/phone_sheet_browser_test.go
+++ b/internal/docs/phone_sheet_browser_test.go
@@ -155,3 +155,30 @@ func TestTheSheetFromAKeyboard(t *testing.T) {
t.Errorf("Escape: sheet open %v, focus on %q, want it closed and focus back on Aa", at.Open, at.Active)
}
}
+
+// openWithKeyboard puts the caret in the second paragraph, raises a
+// 336px keyboard, selects that paragraph and opens the sheet from the
+// capsule's Aa.
+func (s *sheetRig) openWithKeyboard() {
+ s.t.Helper()
+ s.run("the caret, a keyboard", chromedp.Click(chromedp.CSS(`[docs-text] p:last-child`)), settle,
+ do(`__keyboard(336, 0)`), settle,
+ do(`getSelection().selectAllChildren(document.querySelector('[docs-text] p:last-child'))`), settle,
+ chromedp.Click(chromedp.CSS(`[docs-quickbar-aa]`)), settle)
+ if p := s.probe("sheet open"); !p.Sheet || !p.Kept || p.Focused {
+ s.t.Fatalf("the sheet did not open over a kept selection: %+v", p)
+ }
+}
+
+// Review 2: a tap in the document while the sheet is open closes it:
+// the keyboard comes up with the capsule on it, nothing kept is drawn
+// over the live selection, and Aa is no longer expanded.
+func TestATapInTheDocumentClosesTheSheet(t *testing.T) {
+ s := newSheetRig(t, "simple.bin", "")
+ s.openWithKeyboard()
+ s.run("a tap in the document", chromedp.Click(chromedp.CSS(`[docs-text] p:first-child`)), settle)
+ if p := s.probe("tapped"); p.Sheet || p.Kept || !p.Focused || p.Quick != "keyboard" || p.Expanded != "false" {
+ t.Errorf("after a tap in the document: sheet %v, kept drawn %v, caret %v, quick bar %q, Aa expanded %q; want closed, none, the caret, the capsule, false",
+ p.Sheet, p.Kept, p.Focused, p.Quick, p.Expanded)
+ }
+}