 			Meteor.defer =>
 				template.verifySelection()
 
+	template.enterValue = ->
+		value = template.input.value
+		caret = getCursorPosition(template.input)
+		firstPartValue = value.substr 0, caret
+		lastPartValue = value.substr caret
+
+		firstPartValue = firstPartValue.replace(template.selectorRegex, template.prefix + this.getValue(template.value.curValue, template.data.collection) + template.suffix)
+
+		template.input.value = firstPartValue + lastPartValue
+
+		setCursorPosition template.input, firstPartValue.length
+
 
 Template.messagePopup.onRendered ->
 	this.input = this.data.getInput?()

		if event.which is 13
			template.open.set false

			value = template.input.value
			caret = getCursorPosition(template.input)
			firstPartValue = value.substr 0, caret
			lastPartValue = value.substr caret

			firstPartValue = firstPartValue.replace(template.selectorRegex, template.prefix + this.getValue(template.value.curValue, template.data.collection) + template.suffix)

			template.input.value = firstPartValue + lastPartValue

			setCursorPosition template.input, firstPartValue.length

			event.preventDefault()
			event.stopPropagation()


		template.value.set this._id

		template.enterValue()

		template.open.set false


