 				self.hideToolpad()
 		$('#toolpad').delegate '.cancel', 'click', (e)->
 			self.cancelLinkInput()
-			self.applyOrCancelUrl self.linkRange, $(@).val() if self.linkRange
+			if self.linkRange
+				self.applyOrCancelUrl self.linkRange, $(@).val()
 
 	update: ->
 		self = @

	cancelLinkInput: ->
		$('#toolpad li:first-child').removeClass 'toggled'
	applyOrCancelUrl: (range, url)->
		@selection().removeAllRanges()
		@selection().addRange range
		if url

				@showToolpadOverSelection 'toolpad'
				@restoreSelection 'toolpad'
				@linkRange = @selection().getRangeAt 0
				unless @getSelectedElement().is 'a'
					@applyOrCancelUrl @linkRange, '#'
					@linkRange = @selection().getRangeAt 0
			else
				@hideToolpad()
	showToolpadOverSelection: (prefix='m')->
