From 846fcad292c759aa71c35ee369f2a4386d56f0f7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 13:11:01 -0400 Subject: [PATCH] Keep the description selected after Tab in every browser Browsers like Safari and Firefox place the cursor in a textarea after its focus event, undoing the selection, so Tab from the product into the description left the cursor at the start. The box is now selected on focus, once more after the browser has placed its cursor, and again on the Tab key's release, each only while nothing has been typed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM --- app/views/qbo_estimates/_script.html.erb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/views/qbo_estimates/_script.html.erb b/app/views/qbo_estimates/_script.html.erb index 881f5c0..10376cf 100644 --- a/app/views/qbo_estimates/_script.html.erb +++ b/app/views/qbo_estimates/_script.html.erb @@ -339,8 +339,20 @@ $(function () { $(document).on('mousedown touchstart', function () { tabbedAt = 0; }); $tbody.on('focus', '.qbo-line-description-input, .qbo-line-qty-input, .qbo-line-rate-input', function () { if (Date.now() - tabbedAt > 500) return; - // Right away, so the first key typed already replaces the text - this.select(); + // Right away, so the first key typed already replaces the text; and again once the browser has placed + // its cursor (a textarea, the description, puts it back at the start), unless typing has begun + var box = this, before = box.value; + $(box).data('qboTabbedValue', before); + box.select(); + setTimeout(function () { if (document.activeElement === box && box.value === before) box.select(); }, 0); + }); + // Some browsers (Safari, Firefox) place the cursor after that; the Tab key's release arrives here once they + // have, so select again if nothing was typed yet + $tbody.on('keyup', '.qbo-line-description-input, .qbo-line-qty-input, .qbo-line-rate-input', function (event) { + if (event.key !== 'Tab') return; + var tabbed = $(this).data('qboTabbedValue'); + $(this).removeData('qboTabbedValue'); + if (tabbed !== undefined && this.value === tabbed) this.select(); }); // ---- line events ----