       @ace.focus()
       @ace.resize()
     , timeout
+
+  newSession: (code) ->
+    doc = new EditSession code or ''
+    doc.setUndoManager new UndoManager
+    doc
 
   copy: ->
     editor = @ace

activeWindow = App.activeWindow

ace = require 'ace/ace'

module.exports =
class Editor extends Pane

    if File.isDirectory @filename
      File.changeWorkingDirectory @filename
      activeWindow.setTitle _.last @filename.split '/'
      @ace.setSession @newSession()
      activeWindow.setDirty false
    else
      if /png|jpe?g|gif/i.test @filename
        App.openURL @filename
      else
        activeWindow.setTitle _.last @filename.split '/'
        @sessions[@filename] or= @newSession File.read @filename
        @ace.setSession @sessions[@filename]
        activeWindow.setDirty false
    @ace._emit 'open', { @filename }

