Web: back to the grid means back to the cell's text holder; Bold no longer keeps the keyboard
Review #72 consideration 11. SheetsGrid.focus() (after a menu item, a
paste, the formula bar) focused the grid host, not typestart's holder, so
a dead key or input method did not compose from the first key until the
next selection; it now places and focuses the holder. A toolbar button
clicked with the pointer (Bold, say) kept focus and typing went nowhere
(pre-existing): it hands the keyboard back to the cell; one reached with
the keyboard keeps it. The holder's accessible name is the cell's
reference and value ("A1, 42"), not just its text.
TestFirstKeystrokeTypesInABrowser now clicks Bold, types ´ then e, and
reads the holder's name; it fails without this.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+46
−2
internal/sheets/static/commands.js+4 −1internal/sheets/static/typestart.js+18 −1internal/sheets/typestart_browser_test.go+24 −0
diff --git a/internal/sheets/static/commands.js b/internal/sheets/static/commands.js| index d6ad716..efae613 100644 |
| --- a/internal/sheets/static/commands.js |
| +++ b/internal/sheets/static/commands.js |
| @@ -174,7 +174,10 @@ |
| e.preventDefault(); |
| run(el.dataset.cmd, el.dataset.value !== undefined ? el.dataset.value : el.dataset.fn); |
| var panel = el.closest('[data-tool-menu]'); |
| - if (!panel) return; |
| + /* A toolbar button clicked with the pointer keeps focus, so typing |
| + * after Bold went nowhere; the keyboard goes back to the cell. A |
| + * button reached with the keyboard keeps it, to reach the next. */ |
| + if (!panel) { if (e.detail > 0) g.focus(); return; } |
| /* Closing the panel leaves focus on a button inside a closed |
| * <details>, which drops it to <body> — so the keyboard ends up |
| * at the top of the document after picking a colour. Hand it back |
diff --git a/internal/sheets/static/typestart.js b/internal/sheets/static/typestart.js| index 48fc8e2..5080e2b 100644 |
| --- a/internal/sheets/static/typestart.js |
| +++ b/internal/sheets/static/typestart.js |
| @@ -97,13 +97,22 @@ |
| holder.addEventListener('input', function (e) { if (!e.isComposing) rescue(); }); |
| holder.addEventListener('compositionend', function () { setTimeout(rescue, 0); }); |
| + function colName(c) { |
| + var s = ''; |
| + for (c += 1; c > 0; c = Math.floor((c - 1) / 26)) s = String.fromCharCode(65 + (c - 1) % 26) + s; |
| + return s; |
| + } |
| + |
| + /* Over the cell, so an input method's candidates appear beside it, and |
| + * named like it, so a screen reader still hears which cell this is. */ |
| function place(sel) { |
| var td = sel && cellAt(sel); |
| if (!td) return; |
| var box = td.getBoundingClientRect(); |
| holder.style.left = Math.round(box.left) + 'px'; |
| holder.style.top = Math.round(box.top) + 'px'; |
| - holder.setAttribute('aria-label', td.textContent ? td.textContent : 'Empty cell'); |
| + var ref = colName(sel.c) + (sel.r + 1); |
| + holder.setAttribute('aria-label', td.textContent ? ref + ', ' + td.textContent : ref); |
| } |
| /* After the browser's own focus move for the click that selected. */ |
| @@ -120,6 +129,14 @@ |
| if (!g || !g.mayWrite) return; |
| surface.appendChild(holder); |
| g.onSelection(claim); |
| + /* Every "back to the grid" (after a menu item, a paste, the formula |
| + * bar) lands on the holder, so the next key composes from the first. */ |
| + var focusHost = g.focus; |
| + g.focus = function () { |
| + if (!idle()) return focusHost(); |
| + place(g.selection()); |
| + holder.focus({ preventScroll: true }); |
| + }; |
| /* An edit closed (Enter, Tab, Escape, a click away): the page has the |
| * keyboard again, so the holder takes it back. */ |
| document.addEventListener('focusout', function (e) { |
diff --git a/internal/sheets/typestart_browser_test.go b/internal/sheets/typestart_browser_test.go| index 2ef6e1b..02d52b4 100644 |
| --- a/internal/sheets/typestart_browser_test.go |
| +++ b/internal/sheets/typestart_browser_test.go |
| @@ -144,6 +144,30 @@ func TestFirstKeystrokeTypesInABrowser(t *testing.T) { |
| run("Enter", append(press("Enter", "Enter", 13, "\r"), settle)...) |
| saved(2, "か") |
| + // Review #72, 11: after a toolbar button (Bold) the keyboard is back |
| + // on the cell's holder, so a dead key composes from the first key. |
| + selectCell(0) |
| + var holder bool |
| + run("Bold with the pointer", |
| + chromedp.Click(chromedp.CSS(`button[data-tool][data-cmd="bold"]`)), |
| + chromedp.Sleep(100*time.Millisecond), |
| + evalInto(&holder, `document.activeElement && document.activeElement.hasAttribute('data-type-holder')`), |
| + ) |
| + if !holder { |
| + t.Fatal("after Bold the keyboard is on the button: typing goes nowhere") |
| + } |
| + run("dead key after Bold", key(input.DispatchKeyEventTypeRawKeyDown, "Dead", "KeyE", 69, "", 1), compose("´"), |
| + key(input.DispatchKeyEventTypeKeyUp, "Dead", "KeyE", 69, "", 1), commit("é"), settle) |
| + if got := value(0); got != "é" { |
| + t.Fatalf("´ then e after Bold: the editor holds %q, want é", got) |
| + } |
| + run("Escape", append(press("Escape", "Escape", 27, ""), settle)...) |
| + var label string |
| + run("the holder names its cell", chromedp.Sleep(50*time.Millisecond), evalInto(&label, `document.querySelector('[data-type-holder]').getAttribute('aria-label')`)) |
| + if label != "A1, xy" { |
| + t.Errorf("the holder reads %q to a screen reader, want the cell's reference and value", label) |
| + } |
| + |
| // Double-click and F2 keep the cell. (Enter on a selected cell moves |
| // down, as in Excel; that is unchanged.) |
| run("double-click", chromedp.DoubleClick(chromedp.CSS(cell(3))), settle) |