Skip to content

autocomplete messes up the caret position in IE9 #95

banku opened this Issue Aug 15, 2012 · 2 comments

2 participants

banku commented Aug 15, 2012

I am using the latest version of the keyboard (Version 1.12) and autocomplete extension (v1.3).

Steps to reproduce bug: Have a textbox attached to keyboard with autocomplete plug in. Set focus on the textbox and add one or two characters using the virtual keyboard so that the autocomplete suggestions show up. Select an autocomplete selection.

Result:The selection shows up on the target textbox and the caret moves to the end which is all good.

Bug: After this, when you move the mouse to a key on the virtual keyboard and then move the mouse out of it, the caret position moves back to it's original position. For e.g. if two characters were entered before using autocomplete, the caret position will go back to the position after 2 characters.

Expected result: Caret position should stay at the end.

I know that this happens when the below code is executed:
.bind('mouseup.keyboard mouseleave.kb touchend.kb touchmove.kb touchcancel.kb', function(){
if (base.isVisible() && base.isCurrent()) { base.$preview.focus(); }
base.mouseRepeat = [false,''];
clearTimeout(base.repeater); // make sure key repeat stops!
if (base.checkCaret) { base.$preview.caret( base.lastCaret.start, base.lastCaret.end ); }
return false;

So I guess that the fix should be setting base.lastCaret properly when the textbox is updated using autocomplete selection. Does that make sense?

banku commented Aug 15, 2012

Adding the line[base.lastCaret = { start: 1, end: ui.item.value.length };] in the jquery.keyboard.extension-autocomplete.js fixes the issue. Here is the code where this line needs to be put in.

.bind('autocompleteselect', function(e,ui){
                    if (base.hasAutocomplete && ui.item.value !== ''){
                        .val( ui.item.value )

                    base.lastCaret = { start: 1, end: ui.item.value.length };
Mottie commented Aug 15, 2012

Thanks for isolating the problem! I'll include it in the next update :)

@Mottie Mottie closed this in dbd7f2d Sep 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.