Skip to content

Commit 694432d

Browse files
committed
fix fast typing in IE. fixes select2#949
1 parent 26f4160 commit 694432d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

select2.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,11 +1716,24 @@ the specific language governing permissions and limitations under the Apache Lic
17161716

17171717
// single
17181718
opening: function () {
1719+
var el, range;
17191720
this.parent.opening.apply(this, arguments);
17201721
if (this.showSearchInput !== false) {
1722+
// IE appends focusser.val() at the end of field :/ so we manually insert it at the beginning using a range
1723+
// all other browsers handle this just fine
1724+
17211725
this.search.val(this.focusser.val());
17221726
}
17231727
this.search.focus();
1728+
// in IE we have to move the cursor to the end after focussing, otherwise it will be at the beginning and
1729+
// new text will appear *before* focusser.val()
1730+
el = this.search.get(0);
1731+
if (el.createTextRange) {
1732+
range = el.createTextRange();
1733+
range.collapse(false);
1734+
range.select();
1735+
}
1736+
17241737
this.focusser.prop("disabled", true).val("");
17251738
this.updateResults(true);
17261739
this.opts.element.trigger($.Event("select2-open"));

0 commit comments

Comments
 (0)