typeahead.js icon indicating copy to clipboard operation
typeahead.js copied to clipboard

Preserve cursor position after new typehead value is set

Open marianban opened this issue 11 years ago • 4 comments

I'm just trying to integrate typehead.js with angular.js. To achieve this I have to update typehead value each time my angular model changes, but i realized that there is a small problem with loosing cursor position after typehead('val', newValue) is used. It would be nice if setting new typehead value could preserve the actual mouse cursor position.

marianban avatar Jul 15 '14 07:07 marianban

Quick fix for this issue:

setInputValue: function setInputValue(value, silent) { if (!silent) { var selectionStart = this.$input[0].selectionStart; var selectionEnd = this.$input[0].selectionEnd; } this.$input.val(value); if (!silent) { this.$input[0].setSelectionRange(selectionStart, selectionEnd); } silent ? this.clearHint() : this._checkInputValue(); },

marianban avatar Jul 15 '14 08:07 marianban

To clarify, you're referring to the text cursor? Just want to make sure I understand the issue.

jharding avatar Jul 15 '14 16:07 jharding

Yes, to the text cursor.

marianban avatar Jul 15 '14 17:07 marianban

@marianban is this still open? I'm looking forward to working on this fantastic repository!

KIET7UKE avatar Jul 11 '23 13:07 KIET7UKE