Skip to content

Commit

Permalink
Merge pull request igorescobar#403 from archwyrm/fix-set-caret-for-no…
Browse files Browse the repository at this point in the history
…n-ie

Fix cursor jumping while editing in non-IE browsers
  • Loading branch information
Igor Escobar committed Apr 1, 2016
2 parents f92e8ae + f303b90 commit df109aa
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/jquery.mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@
if (el.is(':focus')) {
var range, ctrl = el.get(0);

range = ctrl.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
// Firefox, WebKit, etc..
if (ctrl.setSelectionRange) {
ctrl.focus();
ctrl.setSelectionRange(pos, pos);
} else { // IE
range = ctrl.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
} catch (e) {}
},
Expand Down

0 comments on commit df109aa

Please sign in to comment.