Skip to content

Commit 5cacdca

Browse files
Zach Shepherdjzaefferer
Zach Shepherd
authored andcommitted
Mask: use setTimeout to work around Chrome caret positioning issue
1 parent 3f23f5e commit 5cacdca

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ui/jquery.ui.mask.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,16 @@ $.widget( "ui.mask", {
8080
if ( begin !== undefined ) {
8181
end = ( end === undefined ) ? begin : end;
8282
if ( dom.setSelectionRange ) {
83-
dom.setSelectionRange( begin, end );
83+
/* Chrome fires off the focus events before positioning the
84+
cursor based on where the user clicked. This is annoying
85+
because, in the case of tyring to position the cursor at
86+
the beginning of an empty input, the eventual positioning
87+
based on the user's click overrides whatever we do here.
88+
There's no good fix for this except to wait until the
89+
click processesing resolves and _then_ reposition things. */
90+
setTimeout(function(){
91+
dom.setSelectionRange( begin, end );
92+
}, /* yes, zero is long enough */ 0);
8493
} else if ( dom.createTextRange ) {
8594
range = dom.createTextRange();
8695
range.collapse( true );

0 commit comments

Comments
 (0)