mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Opening a previously opened url restores the same buffer and session.
This commit is contained in:
@@ -37,6 +37,18 @@ describe "Editor", ->
|
||||
fileContents = fs.read(filePath)
|
||||
expect(editor.getAceSession().getValue()).toBe fileContents
|
||||
|
||||
it "restores the ace edit session for a previously assigned buffer", ->
|
||||
buffer = new Buffer filePath
|
||||
editor.setBuffer buffer
|
||||
|
||||
aceSession = editor.getAceSession()
|
||||
|
||||
editor.setBuffer new Buffer(tempFilePath)
|
||||
expect(editor.getAceSession()).not.toBe(aceSession)
|
||||
|
||||
editor.setBuffer(buffer)
|
||||
expect(editor.getAceSession()).toBe aceSession
|
||||
|
||||
it "sets the language mode based on the file extension", ->
|
||||
buffer = new Buffer "something.js"
|
||||
editor.setBuffer buffer
|
||||
|
||||
@@ -19,6 +19,11 @@ describe "Project", ->
|
||||
beforeEach ->
|
||||
absolutePath = require.resolve('fixtures/dir/a')
|
||||
|
||||
it "always returns the same buffer for the same canonical path", ->
|
||||
buffer = project.open(absolutePath)
|
||||
expect(project.open(absolutePath)).toBe buffer
|
||||
expect(project.open('a')).toBe buffer
|
||||
|
||||
describe "when given an absolute path", ->
|
||||
it "returns a buffer for the given path", ->
|
||||
expect(project.open(absolutePath).url).toBe absolutePath
|
||||
@@ -27,3 +32,10 @@ describe "Project", ->
|
||||
it "returns a buffer for the given path (relative to the project root)", ->
|
||||
expect(project.open('a').url).toBe absolutePath
|
||||
|
||||
describe ".resolve(path)", ->
|
||||
it "returns an absolute path based on the project's root", ->
|
||||
absolutePath = require.resolve('fixtures/dir/a')
|
||||
expect(project.resolve('a')).toBe absolutePath
|
||||
expect(project.resolve(absolutePath + '/../a')).toBe absolutePath
|
||||
expect(project.resolve('a/../a')).toBe absolutePath
|
||||
|
||||
|
||||
@@ -25,15 +25,13 @@ describe "fs", ->
|
||||
|
||||
describe "when recursive is true", ->
|
||||
it "returns a promise that resolves to the recursive contents of that directory that are files", ->
|
||||
waitsFor (complete) ->
|
||||
waitsForPromise ->
|
||||
fs.async.listFiles(directoryPath, true).done (result) ->
|
||||
expect(result).toEqual (path for path in fs.list(directoryPath, true) when fs.isFile(path))
|
||||
complete()
|
||||
|
||||
describe "when recursive is false", ->
|
||||
it "returns a promise that resolves to the contents of that directory that are files", ->
|
||||
waitsFor (complete) ->
|
||||
waitsForPromise ->
|
||||
fs.async.listFiles(directoryPath).done (result) ->
|
||||
expect(result).toEqual (path for path in fs.list(directoryPath) when fs.isFile(path))
|
||||
complete()
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user