Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

autocomplete messes up the caret position in IE9 #95

Closed
banku opened this issue Aug 15, 2012 · 2 comments
Closed

autocomplete messes up the caret position in IE9 #95

banku opened this issue Aug 15, 2012 · 2 comments
Labels

Comments

@banku
Copy link

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
Copy link
Author

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 !== ''){
                        base.$preview
                        .val( ui.item.value )
                        .focus();

                    base.lastCaret = { start: 1, end: ui.item.value.length };
                }
            });

@Mottie
Copy link
Owner

Mottie commented Aug 15, 2012

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

@Mottie Mottie closed this as completed in dbd7f2d Sep 10, 2012
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants