Playing a bit, I come up with that code.
Live demo (jsfiddle)
$('.omnitype').each(function() {
var $omnitype = $(this);
$omnitype.typeahead({
source: mySource,
items: 4,
sorter: function(items) {
// Bootstrap code
/* ... */
// Modified code (delay the return of sorted)
var sorted = beginswith.concat(caseSensitive, caseInsensitive);
// if there is a first element, we fill the input select what we added
var first = sorted.length && sorted[0];
if (first) {
var origin = this.$element.val();
this.$element.val(first);
createSelection(this.$element.get(0), origin.length, first.length);
}
// back to the intended behavior
return sorted;
}
});
});
I used this answer to provide the createSelection
function (not sure if really needed).
Still needs quite some tweaking, as the keys doesn't work as expected. It may be easier to recode the whole plugin with some checking that would give naturally the intuitive behavior.
Or you may be able to catch the key events before the plugin and do what is appropriate.