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

    else
      elem.attachEvent 'on'+event, genOp


    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
