 
 		$('body').delegate '#editor', 'click', (e)->
 			$(@).focus()
+
+		# toolpad
+		$('body').delegate '#editor', 'mouseup', (e)=>
+			sel = @selection()
+			if sel.rangeCount > 0
+				range = sel.getRangeAt 0
+				unless range.collapsed
+					@saveSelection 'm'
+					@showToolpadOverSelection 'm'
+					@restoreSelection 'm'
 
 	update: ->
 		self = @

				jqel.remove()
				@restoreSelection()
			else
				console.log jqel.html()
				newEl = $("<#{tag}>").html jqel.html()
				newEl.attr 'name', jqel.attr 'name'
				newEl.attr 'class', jqel.attr 'class'
				console.log newEl.html()
				jqel.after(newEl)
				jqel.remove()
				@restoreSelection()


	selection: ->
		window.getSelection() if window.getSelection
	saveSelection: (prefix='cursor')->
		sel = @selection()
		if sel.getRangeAt && sel.rangeCount
			$('#'+prefix+'Start').remove()
			$('#'+prefix+'End').remove()
			range = sel.getRangeAt 0
			cursorStart = document.createElement 'span'
			cursorStart.id = prefix+'Start'
			range.insertNode cursorStart
			if !range.collapsed
				cursorEnd = document.createElement 'span'
				cursorEnd.id = prefix+'End'
				range.collapse()
				range.insertNode cursorEnd
	restoreSelection: (prefix='cursor')->
		cursorStart = document.getElementById prefix+'Start'
		cursorEnd = document.getElementById prefix+'End'
		range = document.createRange()
		if cursorStart
			sel = @selection()
