Rename Project.open to Project.buildEditSessionForPath

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-07-18 11:19:25 -07:00
parent 522149c84d
commit d36873f702
11 changed files with 51 additions and 46 deletions

View File

@@ -17,6 +17,10 @@ describe "editor.", ->
window.shutdown()
delete atom.rootViewStates[$windowNumber]
describe "opening-buffers.", ->
benchmark "300-line-file.", ->
buffer = rootView.project.bufferForPath('medium.coffee')
describe "empty-file.", ->
benchmark "insert-delete", ->
editor.insertText('x')
@@ -24,7 +28,7 @@ describe "editor.", ->
describe "300-line-file.", ->
beforeEach ->
editor.edit rootView.project.open('medium.coffee')
editor.edit rootView.project.buildEditSessionForPath('medium.coffee')
describe "at-begining.", ->
benchmark "insert-delete", ->
@@ -45,11 +49,11 @@ describe "editor.", ->
describe "9000-line-file.", ->
benchmark "opening.", 5, ->
editor.edit rootView.project.open('huge.js')
editor.edit rootView.project.buildEditSessionForPath('huge.js')
describe "after-opening.", ->
beforeEach ->
editor.edit rootView.project.open('huge.js')
editor.edit rootView.project.buildEditSessionForPath('huge.js')
benchmark "moving-to-eof.", 1, ->
editor.moveCursorToBottom()

View File

@@ -7,7 +7,7 @@ describe "EditSession", ->
beforeEach ->
buffer = new Buffer()
editSession = fixturesProject.open('sample.js', autoIndent: false)
editSession = fixturesProject.buildEditSessionForPath('sample.js', autoIndent: false)
buffer = editSession.buffer
lineLengths = buffer.getLines().map (line) -> line.length
@@ -1319,7 +1319,7 @@ describe "EditSession", ->
expect(editSession.getSelectedBufferRanges()).toEqual [[[1, 6], [1, 6]], [[1, 18], [1, 18]]]
it "restores selected ranges even when the change occurred in another edit session", ->
otherEditSession = fixturesProject.open(editSession.getPath())
otherEditSession = fixturesProject.buildEditSessionForPath(editSession.getPath())
otherEditSession.setSelectedBufferRange([[2, 2], [3, 3]])
otherEditSession.delete()

View File

@@ -14,7 +14,7 @@ describe "Editor", ->
getLineHeight = ->
return cachedLineHeight if cachedLineHeight?
editorForMeasurement = new Editor(editSession: rootView.project.open('sample.js'))
editorForMeasurement = new Editor(editSession: rootView.project.buildEditSessionForPath('sample.js'))
editorForMeasurement.attachToDom()
cachedLineHeight = editorForMeasurement.lineHeight
editorForMeasurement.remove()
@@ -49,7 +49,7 @@ describe "Editor", ->
rootView.height(8 * editor.lineHeight)
rootView.width(50 * editor.charWidth)
editor.edit(rootView.project.open('two-hundred.txt'))
editor.edit(rootView.project.buildEditSessionForPath('two-hundred.txt'))
editor.setCursorScreenPosition([5, 1])
editor.scrollTop(1.5 * editor.lineHeight)
editor.scrollView.scrollLeft(44)
@@ -113,7 +113,7 @@ describe "Editor", ->
describe ".remove()", ->
it "removes subscriptions from all edit session buffers", ->
previousEditSession = editor.activeEditSession
otherEditSession = rootView.project.open(rootView.project.resolve('sample.txt'))
otherEditSession = rootView.project.buildEditSessionForPath(rootView.project.resolve('sample.txt'))
expect(previousEditSession.buffer.subscriptionCount()).toBeGreaterThan 1
editor.edit(otherEditSession)
@@ -125,7 +125,7 @@ describe "Editor", ->
describe "when 'close' is triggered", ->
it "closes active edit session and loads next edit session", ->
editor.edit(rootView.project.open())
editor.edit(rootView.project.buildEditSessionForPath())
editSession = editor.activeEditSession
spyOn(editSession, 'destroy').andCallThrough()
spyOn(editor, "remove").andCallThrough()
@@ -161,7 +161,7 @@ describe "Editor", ->
otherEditSession = null
beforeEach ->
otherEditSession = rootView.project.open()
otherEditSession = rootView.project.buildEditSessionForPath()
describe "when the edit session wasn't previously assigned to this editor", ->
it "adds edit session to editor", ->
@@ -197,10 +197,10 @@ describe "Editor", ->
beforeEach ->
session0 = editor.activeEditSession
editor.edit(rootView.project.open('sample.txt'))
editor.edit(rootView.project.buildEditSessionForPath('sample.txt'))
session1 = editor.activeEditSession
editor.edit(rootView.project.open('two-hundred.txt'))
editor.edit(rootView.project.buildEditSessionForPath('two-hundred.txt'))
session2 = editor.activeEditSession
describe ".setActiveEditSessionIndex(index)", ->
@@ -277,7 +277,7 @@ describe "Editor", ->
describe "when the current buffer has no path", ->
selectedFilePath = null
beforeEach ->
editor.edit(rootView.project.open())
editor.edit(rootView.project.buildEditSessionForPath())
expect(editor.getPath()).toBeUndefined()
editor.getBuffer().setText 'Save me to a new path'
@@ -357,7 +357,7 @@ describe "Editor", ->
spyOn(editor, 'pane').andReturn(fakePane)
it "calls the corresponding split method on the containing pane with a new editor containing a copy of the active edit session", ->
editor.edit project.open("sample.txt")
editor.edit project.buildEditSessionForPath("sample.txt")
editor.splitUp()
expect(fakePane.splitUp).toHaveBeenCalled()
[newEditor] = fakePane.splitUp.argsForCall[0]
@@ -404,7 +404,7 @@ describe "Editor", ->
it "emits event when editor receives a new buffer", ->
eventHandler = jasmine.createSpy('eventHandler')
editor.on 'editor-path-change', eventHandler
editor.edit(rootView.project.open(path))
editor.edit(rootView.project.buildEditSessionForPath(path))
expect(eventHandler).toHaveBeenCalled()
it "stops listening to events on previously set buffers", ->
@@ -412,7 +412,7 @@ describe "Editor", ->
oldBuffer = editor.getBuffer()
editor.on 'editor-path-change', eventHandler
editor.edit(rootView.project.open(path))
editor.edit(rootView.project.buildEditSessionForPath(path))
expect(eventHandler).toHaveBeenCalled()
eventHandler.reset()
@@ -1010,7 +1010,7 @@ describe "Editor", ->
expect(editor.bufferPositionForScreenPosition(editor.getCursorScreenPosition())).toEqual [3, 60]
it "does not wrap the lines of any newly assigned buffers", ->
otherEditSession = rootView.project.open()
otherEditSession = rootView.project.buildEditSessionForPath()
otherEditSession.buffer.setText([1..100].join(''))
editor.edit(otherEditSession)
expect(editor.renderedLines.find('.line').length).toBe(1)
@@ -1046,7 +1046,7 @@ describe "Editor", ->
expect(editor.getCursorScreenPosition()).toEqual [11, 0]
it "calls .setSoftWrapColumn() when the editor is attached because now its dimensions are available to calculate it", ->
otherEditor = new Editor(editSession: rootView.project.open('sample.js'))
otherEditor = new Editor(editSession: rootView.project.buildEditSessionForPath('sample.js'))
spyOn(otherEditor, 'setSoftWrapColumn')
otherEditor.setSoftWrap(true)
@@ -1344,7 +1344,7 @@ describe "Editor", ->
describe "when autoscrolling at the end of the document", ->
it "renders lines properly", ->
editor.edit(rootView.project.open('two-hundred.txt'))
editor.edit(rootView.project.buildEditSessionForPath('two-hundred.txt'))
editor.attachToDom(heightInLines: 5.5)
expect(editor.renderedLines.find('.line').length).toBe 8
@@ -1510,7 +1510,7 @@ describe "Editor", ->
describe "folding", ->
beforeEach ->
editSession = rootView.project.open('two-hundred.txt')
editSession = rootView.project.buildEditSessionForPath('two-hundred.txt')
buffer = editSession.buffer
editor.edit(editSession)
editor.attachToDom()
@@ -1593,8 +1593,8 @@ describe "Editor", ->
describe ".getOpenBufferPaths()", ->
it "returns the paths of all non-anonymous buffers with edit sessions on this editor", ->
editor.edit(project.open('sample.txt'))
editor.edit(project.open('two-hundred.txt'))
editor.edit(project.open())
editor.edit(project.buildEditSessionForPath('sample.txt'))
editor.edit(project.buildEditSessionForPath('two-hundred.txt'))
editor.edit(project.buildEditSessionForPath())
paths = editor.getOpenBufferPaths().map (path) -> project.relativize(path)
expect(paths).toEqual = ['sample.js', 'sample.txt', 'two-hundred.txt']

View File

@@ -11,8 +11,8 @@ describe "Project", ->
describe "when editSession is destroyed", ->
it "removes edit session and calls destroy on buffer (if buffer is not referenced by other edit sessions)", ->
editSession = project.open("a")
anotherEditSession = project.open("a")
editSession = project.buildEditSessionForPath("a")
anotherEditSession = project.buildEditSessionForPath("a")
buffer = editSession.buffer
spyOn(buffer, 'destroy').andCallThrough()
@@ -27,7 +27,7 @@ describe "Project", ->
expect(buffer.destroy).toHaveBeenCalled()
expect(project.editSessions.length).toBe 0
describe ".open(path)", ->
describe ".buildEditSessionForPath(path)", ->
[absolutePath, newBufferHandler, newEditSessionHandler] = []
beforeEach ->
absolutePath = require.resolve('fixtures/dir/a')
@@ -38,30 +38,30 @@ describe "Project", ->
describe "when given an absolute path that hasn't been opened previously", ->
it "returns a new edit session for the given path and emits 'new-buffer' and 'new-edit-session' events", ->
editSession = project.open(absolutePath)
editSession = project.buildEditSessionForPath(absolutePath)
expect(editSession.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
describe "when given a relative path that hasn't been opened previously", ->
it "returns a new edit session for the given path (relative to the project root) and emits 'new-buffer' and 'new-edit-session' events", ->
editSession = project.open('a')
editSession = project.buildEditSessionForPath('a')
expect(editSession.buffer.getPath()).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
describe "when passed the path to a buffer that has already been opened", ->
it "returns a new edit session containing previously opened buffer and emits a 'new-edit-session' event", ->
editSession = project.open(absolutePath)
editSession = project.buildEditSessionForPath(absolutePath)
newBufferHandler.reset()
expect(project.open(absolutePath).buffer).toBe editSession.buffer
expect(project.open('a').buffer).toBe editSession.buffer
expect(project.buildEditSessionForPath(absolutePath).buffer).toBe editSession.buffer
expect(project.buildEditSessionForPath('a').buffer).toBe editSession.buffer
expect(newBufferHandler).not.toHaveBeenCalled()
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
describe "when not passed a path", ->
it "returns a new edit session and emits 'new-buffer' and 'new-edit-session' events", ->
editSession = project.open()
editSession = project.buildEditSessionForPath()
expect(editSession.buffer.getPath()).toBeUndefined()
expect(newBufferHandler).toHaveBeenCalledWith(editSession.buffer)
expect(newEditSessionHandler).toHaveBeenCalledWith editSession

View File

@@ -75,10 +75,10 @@ describe "RootView", ->
editor2 = editor1.splitRight()
editor3 = editor2.splitRight()
editor4 = editor2.splitDown()
editor2.edit(rootView.project.open('dir/b'))
editor3.edit(rootView.project.open('sample.js'))
editor2.edit(rootView.project.buildEditSessionForPath('dir/b'))
editor3.edit(rootView.project.buildEditSessionForPath('sample.js'))
editor3.setCursorScreenPosition([2, 3])
editor4.edit(rootView.project.open('sample.txt'))
editor4.edit(rootView.project.buildEditSessionForPath('sample.txt'))
editor4.setCursorScreenPosition([0, 2])
rootView.attachToDom()
editor2.focus()
@@ -455,7 +455,7 @@ describe "RootView", ->
editor2 = rootView.getActiveEditor().splitLeft()
path = rootView.project.resolve('b')
editor2.edit(rootView.project.open(path))
editor2.edit(rootView.project.buildEditSessionForPath(path))
expect(pathChangeHandler).toHaveBeenCalled()
expect(document.title).toBe rootView.project.resolve(path)

View File

@@ -10,7 +10,7 @@ describe "Autocomplete", ->
miniEditor = null
beforeEach ->
editor = new Editor(editSession: fixturesProject.open('sample.js'))
editor = new Editor(editSession: fixturesProject.buildEditSessionForPath('sample.js'))
autocomplete = new Autocomplete(editor)
miniEditor = autocomplete.miniEditor
@@ -357,7 +357,7 @@ describe "Autocomplete", ->
expect(wordList).toContain "quicksort"
expect(wordList).not.toContain "Some"
editor.edit(fixturesProject.open('sample.txt'))
editor.edit(fixturesProject.buildEditSessionForPath('sample.txt'))
wordList = autocomplete.wordList
expect(wordList).not.toContain "quicksort"
@@ -365,7 +365,7 @@ describe "Autocomplete", ->
it 'stops listening to previous buffers change events', ->
previousBuffer = editor.getBuffer()
editor.edit(fixturesProject.open('sample.txt'))
editor.edit(fixturesProject.buildEditSessionForPath('sample.txt'))
spyOn(autocomplete, "buildWordList")
previousBuffer.change([[0,0],[0,1]], "sauron")

View File

@@ -9,7 +9,7 @@ describe "CommandInterpreter", ->
beforeEach ->
project = new Project(fixturesProject.resolve('dir/'))
interpreter = new CommandInterpreter(fixturesProject)
editSession = fixturesProject.open('sample.js')
editSession = fixturesProject.buildEditSessionForPath('sample.js')
buffer = editSession.buffer
afterEach ->
@@ -320,7 +320,7 @@ describe "CommandInterpreter", ->
runs ->
expect(operations.length).toBeGreaterThan 3
for operation in operations
editSession = project.open(operation.getPath())
editSession = project.buildEditSessionForPath(operation.getPath())
operation.execute(editSession)
expect(editSession.getSelectedText()).toMatch /a+/
editSession.destroy()

View File

@@ -122,7 +122,7 @@ describe 'FuzzyFinder', ->
describe "when the active editor only contains edit sessions for anonymous buffers", ->
it "does not open", ->
editor = rootView.getActiveEditor()
editor.edit(rootView.project.open())
editor.edit(rootView.project.buildEditSessionForPath())
editor.loadPreviousEditSession()
editor.destroyActiveEditSession()
expect(editor.getOpenBufferPaths().length).toBe 0

View File

@@ -14,7 +14,7 @@ class EditSession
@idCounter: 1
@deserialize: (state, project) ->
session = project.open(state.buffer)
session = project.buildEditSessionForPath(state.buffer)
session.setScrollTop(state.scrollTop)
session.setScrollLeft(state.scrollLeft)
session.setCursorScreenPosition(state.cursorScreenPosition)

View File

@@ -21,6 +21,7 @@ class Project
constructor: (path) ->
@setPath(path)
@editSessions = []
@buffer = []
@setTabText(' ')
@setAutoIndent(true)
@setSoftTabs(true)
@@ -84,7 +85,7 @@ class Project
getSoftWrap: -> @softWrap
setSoftWrap: (@softWrap) ->
open: (filePath, editSessionOptions={}) ->
buildEditSessionForPath: (filePath, editSessionOptions={}) ->
@buildEditSession(@bufferForPath(filePath), editSessionOptions)
buildEditSession: (buffer, editSessionOptions) ->

View File

@@ -96,7 +96,7 @@ class RootView extends View
allowActiveEditorChange = options.allowActiveEditorChange ? false
unless editSession = @openInExistingEditor(path, allowActiveEditorChange)
editSession = @project.open(path)
editSession = @project.buildEditSessionForPath(path)
editor = new Editor({editSession})
pane = new Pane(editor)
@panes.append(pane)
@@ -120,7 +120,7 @@ class RootView extends View
editor.focus()
return editSession
editSession = @project.open(path)
editSession = @project.buildEditSessionForPath(path)
activeEditor.edit(editSession)
editSession