diff --git a/app/assets/javascripts/discourse/lib/autocomplete.js.es6 b/app/assets/javascripts/discourse/lib/autocomplete.js.es6 index cbaffc2b85c..3c435b54b10 100644 --- a/app/assets/javascripts/discourse/lib/autocomplete.js.es6 +++ b/app/assets/javascripts/discourse/lib/autocomplete.js.es6 @@ -130,10 +130,13 @@ export default function(options) { if (options.transformComplete) { term = options.transformComplete(term); } - var text = me.val(); - text = text.substring(0, completeStart) + (options.key || "") + term + ' ' + text.substring(completeEnd + 1, text.length); - me.val(text); - Discourse.Utilities.setCaretPosition(me[0], completeStart + 1 + term.length); + + if (term) { + var text = me.val(); + text = text.substring(0, completeStart) + (options.key || "") + term + ' ' + text.substring(completeEnd + 1, text.length); + me.val(text); + Discourse.Utilities.setCaretPosition(me[0], completeStart + 1 + term.length); + } } } closeAutocomplete();