     else
       elem.attachEvent 'on'+event, genOp
 
+  elem.detach_share = =>
+    @removeListener 'insert', insert_listener
+    @removeListener 'delete', delete_listener
+
+    for event in ['textInput', 'keydown', 'keyup', 'select', 'cut', 'paste']
+      if elem.removeEventListener
+        elem.removeEventListener event, genOp, false
+      else
+        elem.detachEvent 'on'+event, genOp

    prevvalue = elem.value.replace /\r\n/g, '\n'
    replaceText prevvalue[...pos] + text + prevvalue[pos..], transformCursor
  
  @on 'delete', (pos, text) ->
    transformCursor = (cursor) ->
      if pos < cursor
        cursor - Math.min(text.length, cursor - pos)

    elem.scrollTop = scrollTop if elem.scrollTop != scrollTop
    [elem.selectionStart, elem.selectionEnd] = newSelection

  @on 'insert', insert_listener = (pos, text) ->
    transformCursor = (cursor) ->
      if pos < cursor
        cursor + text.length
