FIX: handle paste events for auto completed fields
This commit is contained in:
parent
0e7be81e60
commit
168c690427
|
@ -264,12 +264,17 @@ export default function(options) {
|
||||||
closeAutocomplete();
|
closeAutocomplete();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(this).on('paste', function() {
|
||||||
|
_.delay(function(){
|
||||||
|
me.trigger("keydown");
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
|
|
||||||
$(this).keypress(function(e) {
|
$(this).keypress(function(e) {
|
||||||
|
|
||||||
if (!options.key) return;
|
if (!options.key) return;
|
||||||
|
|
||||||
// keep hunting backwards till you hit a
|
// keep hunting backwards till you hit a the @ key
|
||||||
if (e.which === options.key.charCodeAt(0)) {
|
if (e.which === options.key.charCodeAt(0)) {
|
||||||
var caretPosition = Discourse.Utilities.caretPosition(me[0]);
|
var caretPosition = Discourse.Utilities.caretPosition(me[0]);
|
||||||
var prevChar = me.val().charAt(caretPosition - 1);
|
var prevChar = me.val().charAt(caretPosition - 1);
|
||||||
|
@ -283,6 +288,10 @@ export default function(options) {
|
||||||
$(this).keydown(function(e) {
|
$(this).keydown(function(e) {
|
||||||
var c, caretPosition, i, initial, next, prev, prevIsGood, stopFound, term, total, userToComplete;
|
var c, caretPosition, i, initial, next, prev, prevIsGood, stopFound, term, total, userToComplete;
|
||||||
|
|
||||||
|
if(e.ctrlKey || e.altKey || e.metaKey){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if(options.allowAny){
|
if(options.allowAny){
|
||||||
// saves us wiring up a change event as well, keypress is while its pressed
|
// saves us wiring up a change event as well, keypress is while its pressed
|
||||||
_.delay(function(){
|
_.delay(function(){
|
||||||
|
@ -393,7 +402,7 @@ export default function(options) {
|
||||||
i.click();
|
i.click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
|
term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
|
||||||
if (e.which >= 48 && e.which <= 90) {
|
if (e.which >= 48 && e.which <= 90) {
|
||||||
|
@ -406,6 +415,8 @@ export default function(options) {
|
||||||
term += (e.shiftKey) ? "|" : "]";
|
term += (e.shiftKey) ? "|" : "]";
|
||||||
} else if (e.which === 222) {
|
} else if (e.which === 222) {
|
||||||
term += (e.shiftKey) ? "\"" : "'";
|
term += (e.shiftKey) ? "\"" : "'";
|
||||||
|
} else if (!e.which) {
|
||||||
|
/* fake event */
|
||||||
} else if (e.which !== 8) {
|
} else if (e.which !== 8) {
|
||||||
term += ",";
|
term += ",";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue