From 3ffe565b3d50539470a05b1f7a65f5fed419daf5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 7 Oct 2026 13:47:09 -0700 Subject: Desktop Send focus: a mouse click leaves the Send button focused, and that blocked the recipient field — only a field you're typing in is protected now (test opens Send with a real click) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- src/app.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/app.js b/src/app.js index 9c227b8..1e77849 100644 --- a/src/app.js +++ b/src/app.js @@ -4725,11 +4725,12 @@ function tabsBar() { // On a desktop (a real pointer, a real keyboard) Send is ready to type into: // the recipient field has the cursor when the tab opens, and the amount field // takes it the moment it appears, so a picked recipient goes straight to -// typing the number. Once per field per visit: it never pulls focus back after -// you've moved on, and never off another field you're in (a zap comment) — -// only off nothing, or (for the amount) off the recipient field that just -// resolved. Phones keep their keyboard down until a tap. -let sendVisit = 0, lastTabSeen = null; +// typing the number. Once per field: it never pulls focus back after you've +// moved on, and never off another field you're in (a zap comment) — only off +// nothing, or (for the amount) off the recipient field that just resolved. +// Leaving Send takes its fields off the page, so coming back builds new ones +// and the cursor lands again, however you left. Phones keep their keyboard +// down until a tap. function focusSendField() { if (matchMedia('(pointer: coarse)').matches) return; const pane = document.querySelector('[data-send-pane]'); @@ -4737,10 +4738,13 @@ function focusSendField() { const amt = pane.querySelector('input[type=number]:not(:disabled)'); const dest = pane.querySelector('textarea.send-dest:not(:disabled)'); const field = amt || dest; - if (!field || field._autoFocused === sendVisit) return; - field._autoFocused = sendVisit; + if (!field || field._autoFocused) return; + field._autoFocused = true; + // Only typing is protected: a clicked button (the Send tab itself keeps the + // focus a mouse click gave it) or a link has nothing to lose. const a = document.activeElement; - if (a && a !== document.body && !(amt && a.classList && a.classList.contains('send-dest'))) return; + const typing = a && a !== document.body && (a.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(a.tagName)); + if (typing && !(amt && a.classList.contains('send-dest'))) return; field.focus(); } @@ -4758,7 +4762,6 @@ function tabContent() { if (detailOpen) return hist; sendFocused = false; const pane = ui.tab === 'receive' ? receiveTab() : sendTab(); - if (ui.tab !== lastTabSeen) { lastTabSeen = ui.tab; if (ui.tab === 'send') sendVisit++; } if (ui.tab === 'send' && pane && pane.setAttribute) { pane.setAttribute('data-send-pane', ''); requestAnimationFrame(focusSendField); -- cgit v1.2.3