diff options
| -rw-r--r-- | src/app.js | 21 | ||||
| -rw-r--r-- | tools/send-enter-keys-test.js | 19 |
2 files changed, 30 insertions, 10 deletions
@@ -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); diff --git a/tools/send-enter-keys-test.js b/tools/send-enter-keys-test.js index 67997c0..aac95f8 100644 --- a/tools/send-enter-keys-test.js +++ b/tools/send-enter-keys-test.js @@ -72,11 +72,28 @@ try { check('back on Spending, history again', !(await lit()), await lit()); console.log('[recipient: Enter picks the top suggestion]'); - await page.evaluate(() => [...document.querySelectorAll('button')].find((b) => b.textContent.trim() === 'Send')?.click()); + // a REAL click: Chrome focuses the button clicked, and the recipient field + // must still take the cursor from it + const openSend = async () => { + for (const b of await page.$$('button')) if ((await b.evaluate((n) => n.textContent.trim())) === 'Send') { await b.click(); return; } + }; + await openSend(); await page.waitForSelector('textarea.send-dest', { timeout: 10000 }); await sleep(300); check('desktop: Send opens with the cursor in the recipient field', await page.evaluate(() => document.activeElement?.matches('textarea.send-dest')), await page.evaluate(() => document.activeElement?.outerHTML.slice(0, 80))); + // away and back, two ways: the cursor lands again each time + await page.evaluate(() => document.activeElement?.blur()); + await page.evaluate(() => [...document.querySelectorAll('button')].find((b) => b.textContent.trim() === 'Receive')?.click()); await sleep(600); + await openSend(); await sleep(600); + check('...again after Receive and back to Send', await page.evaluate(() => document.activeElement?.matches('textarea.send-dest')), + await page.evaluate(() => document.activeElement?.outerHTML.slice(0, 80))); + await page.evaluate(() => document.activeElement?.blur()); + await swipeTo('face-savings'); await sleep(1200); + await swipeTo('face-spending'); await sleep(1200); + await openSend(); await sleep(600); + check('...and after swiping to Savings and back', await page.evaluate(() => document.activeElement?.matches('textarea.send-dest')), + await page.evaluate(() => document.activeElement?.outerHTML.slice(0, 80))); await page.focus('textarea.send-dest'); await page.keyboard.type('adam', { delay: 80 }); let top = ''; |
