       input: editor.getText()
       mode: mode?.name
 
+  resetPrefix: ->
+    @prefix?.listener?.dispose()
+    delete @prefix
+
   moveHistory: (up) ->
     {editor} = @getInput()
     if (editor.getText() or not @prefix?) and @prefix?.pos?[0] isnt Infinity
+      @resetPrefix()
       pos = editor.getCursorBufferPosition()
       text = editor.getTextInRange [[0,0], pos]
       pos = [Infinity, Infinity] if text is ''

      @history.getPrevious @prefix.text
    else
      @history.getNext @prefix.text
    editor.setText next.input
    @setMode @getInput(), next.mode
    editor.setCursorBufferPosition @prefix.pos or [0, 0]


  lastOutput: -> @items[@items.length - (if @getInput() then 2 else 1)]

  input: ->
    @resetPrefix()
    if not @getInput()
      item = type: 'input', input: true
      @push @setMode item
