Opening a previously opened url restores the same buffer and session.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-05 16:33:53 -08:00
parent 12cf511a40
commit 18b9782b16
5 changed files with 38 additions and 11 deletions

View File

@@ -14,6 +14,7 @@ class Editor extends Template
buffer: null
initialize: () ->
@aceSessions = {}
@buildAceEditor()
@setBuffer(new Buffer)
@@ -24,8 +25,10 @@ class Editor extends Template
@aceEditor.destroy()
setBuffer: (@buffer) ->
session = new EditSession(@buffer.aceDocument, @buffer.getMode())
@aceEditor.setSession(session)
@aceEditor.setSession @getAceSessionForBuffer(buffer)
getAceSessionForBuffer: (buffer) ->
@aceSessions[@buffer.url] ?= new EditSession(@buffer.aceDocument, @buffer.getMode())
buildAceEditor: ->
@aceEditor = ace.edit this[0]

View File

@@ -4,17 +4,19 @@ Buffer = require 'buffer'
module.exports =
class Project
buffers: null
constructor: (@url) ->
@buffers = {}
getFilePaths: ->
fs.async.listFiles(@url, true)
open: (filePath) ->
new Buffer(@resolve(filePath))
filePath = @resolve filePath
@buffers[filePath] ?= new Buffer(filePath)
resolve: (filePath) ->
if filePath[0] == '/'
filePath
else
fs.join(@url, filePath)
filePath = fs.join(@url, filePath) unless filePath[0] == '/'
fs.absolute filePath