mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
1 file changed
+14
-2
@@ -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 ----
|
||||
|
||||
Reference in new issue
Block a user