mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Rename Project::open to Project::openSync
…and Project::openAsync to Project::open
This commit is contained in:
@@ -12,7 +12,7 @@ describe "editor.", ->
|
||||
|
||||
rootView.width(1024)
|
||||
rootView.height(768)
|
||||
rootView.open() # open blank editor
|
||||
rootView.openSync() # open blank editor
|
||||
editor = rootView.getActiveView()
|
||||
|
||||
afterEach ->
|
||||
@@ -40,7 +40,7 @@ describe "editor.", ->
|
||||
|
||||
describe "300-line-file.", ->
|
||||
beforeEach ->
|
||||
rootView.open('medium.coffee')
|
||||
rootView.openSync('medium.coffee')
|
||||
|
||||
describe "at-begining.", ->
|
||||
benchmark "insert-delete", ->
|
||||
@@ -171,11 +171,11 @@ describe "editor.", ->
|
||||
|
||||
describe "9000-line-file.", ->
|
||||
benchmark "opening.", 5, ->
|
||||
rootView.open('huge.js')
|
||||
rootView.openSync('huge.js')
|
||||
|
||||
describe "after-opening.", ->
|
||||
beforeEach ->
|
||||
rootView.open('huge.js')
|
||||
rootView.openSync('huge.js')
|
||||
|
||||
benchmark "moving-to-eof.", 1, ->
|
||||
editor.moveCursorToBottom()
|
||||
@@ -210,7 +210,7 @@ describe "TokenizedBuffer.", ->
|
||||
[languageMode, buffer] = []
|
||||
|
||||
beforeEach ->
|
||||
editSession = benchmarkFixturesProject.open('medium.coffee')
|
||||
editSession = benchmarkFixturesProject.openSync('medium.coffee')
|
||||
{ languageMode, buffer } = editSession
|
||||
|
||||
benchmark "construction", 20, ->
|
||||
|
||||
@@ -10,7 +10,7 @@ describe "EditSession replication", ->
|
||||
doc2 = null
|
||||
|
||||
env1.run ->
|
||||
editSession1 = project.open('sample.js')
|
||||
editSession1 = project.openSync('sample.js')
|
||||
editSession1.setScrollTop(5)
|
||||
editSession1.setScrollLeft(5)
|
||||
editSession1.setCursorScreenPosition([0, 5])
|
||||
|
||||
@@ -8,7 +8,7 @@ describe "EditSession", ->
|
||||
|
||||
describe "with an initial line option", ->
|
||||
beforeEach ->
|
||||
editSession = project.open('sample.js', initialLine: 2)
|
||||
editSession = project.openSync('sample.js', initialLine: 2)
|
||||
buffer = editSession.buffer
|
||||
|
||||
it "opens the file and positions the cursor on line 2", ->
|
||||
@@ -17,7 +17,7 @@ describe "EditSession", ->
|
||||
describe "with default options", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('javascript-tmbundle', sync: true)
|
||||
editSession = project.open('sample.js', autoIndent: false)
|
||||
editSession = project.openSync('sample.js', autoIndent: false)
|
||||
buffer = editSession.buffer
|
||||
lineLengths = buffer.getLines().map (line) -> line.length
|
||||
|
||||
@@ -60,7 +60,7 @@ describe "EditSession", ->
|
||||
config.set('editor.tabLength', 4)
|
||||
config.set('editor.softWrap', true)
|
||||
config.set('editor.softTabs', false)
|
||||
editSession1 = project.open('a')
|
||||
editSession1 = project.openSync('a')
|
||||
expect(editSession1.getTabLength()).toBe 4
|
||||
expect(editSession1.getSoftWrap()).toBe true
|
||||
expect(editSession1.getSoftTabs()).toBe false
|
||||
@@ -68,7 +68,7 @@ describe "EditSession", ->
|
||||
config.set('editor.tabLength', 100)
|
||||
config.set('editor.softWrap', false)
|
||||
config.set('editor.softTabs', true)
|
||||
editSession2 = project.open('b')
|
||||
editSession2 = project.openSync('b')
|
||||
expect(editSession2.getTabLength()).toBe 100
|
||||
expect(editSession2.getSoftWrap()).toBe false
|
||||
expect(editSession2.getSoftTabs()).toBe true
|
||||
@@ -1184,7 +1184,7 @@ describe "EditSession", ->
|
||||
expect(selection.isEmpty()).toBeTruthy()
|
||||
|
||||
it "does not share selections between different edit sessions for the same buffer", ->
|
||||
editSession2 = project.open('sample.js')
|
||||
editSession2 = project.openSync('sample.js')
|
||||
editSession.setSelectedBufferRanges([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
|
||||
editSession2.setSelectedBufferRanges([[[8, 7], [6, 5]], [[4, 3], [2, 1]]])
|
||||
expect(editSession2.getSelectedBufferRanges()).not.toEqual editSession.getSelectedBufferRanges()
|
||||
@@ -2033,7 +2033,7 @@ describe "EditSession", ->
|
||||
|
||||
it "does not explode if the current language mode has no comment regex", ->
|
||||
editSession.destroy()
|
||||
editSession = project.open(null, autoIndent: false)
|
||||
editSession = project.openSync(null, autoIndent: false)
|
||||
editSession.setSelectedBufferRange([[4, 5], [4, 5]])
|
||||
editSession.toggleLineCommentsInSelection()
|
||||
expect(buffer.lineForRow(4)).toBe " while(items.length > 0) {"
|
||||
@@ -2356,13 +2356,13 @@ describe "EditSession", ->
|
||||
|
||||
describe "soft-tabs detection", ->
|
||||
it "assigns soft / hard tabs based on the contents of the buffer, or uses the default if unknown", ->
|
||||
editSession = project.open('sample.js', softTabs: false)
|
||||
editSession = project.openSync('sample.js', softTabs: false)
|
||||
expect(editSession.getSoftTabs()).toBeTruthy()
|
||||
|
||||
editSession = project.open('sample-with-tabs.coffee', softTabs: true)
|
||||
editSession = project.openSync('sample-with-tabs.coffee', softTabs: true)
|
||||
expect(editSession.getSoftTabs()).toBeFalsy()
|
||||
|
||||
editSession = project.open(null, softTabs: false)
|
||||
editSession = project.openSync(null, softTabs: false)
|
||||
expect(editSession.getSoftTabs()).toBeFalsy()
|
||||
|
||||
describe ".indentLevelForLine(line)", ->
|
||||
@@ -2391,7 +2391,7 @@ describe "EditSession", ->
|
||||
jsGrammar = syntax.selectGrammar('a.js')
|
||||
syntax.removeGrammar(jsGrammar)
|
||||
|
||||
editSession = project.open('sample.js', autoIndent: false)
|
||||
editSession = project.openSync('sample.js', autoIndent: false)
|
||||
expect(editSession.getGrammar()).toBe syntax.nullGrammar
|
||||
expect(editSession.lineForScreenRow(0).tokens.length).toBe 1
|
||||
|
||||
@@ -2605,7 +2605,7 @@ describe "EditSession", ->
|
||||
expect(editSession.shouldPromptToSave()).toBeFalsy()
|
||||
buffer.setText('changed')
|
||||
expect(editSession.shouldPromptToSave()).toBeTruthy()
|
||||
editSession2 = project.open('sample.js', autoIndent: false)
|
||||
editSession2 = project.openSync('sample.js', autoIndent: false)
|
||||
expect(editSession.shouldPromptToSave()).toBeFalsy()
|
||||
editSession2.destroy()
|
||||
expect(editSession.shouldPromptToSave()).toBeTruthy()
|
||||
|
||||
@@ -12,7 +12,7 @@ describe "Editor replication", ->
|
||||
doc2 = null
|
||||
|
||||
env1.run ->
|
||||
editSession1 = project.open('sample.js')
|
||||
editSession1 = project.openSync('sample.js')
|
||||
editSession1.setSelectedBufferRange([[1, 2], [3, 4]])
|
||||
doc1 = editSession1.getState()
|
||||
doc2 = doc1.clone(env2.site)
|
||||
|
||||
@@ -7,7 +7,7 @@ describe "Editor", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('text-tmbundle', sync: true)
|
||||
atom.activatePackage('javascript-tmbundle', sync: true)
|
||||
editSession = project.open('sample.js')
|
||||
editSession = project.openSync('sample.js')
|
||||
buffer = editSession.buffer
|
||||
editor = new Editor(editSession)
|
||||
editor.lineOverdraw = 2
|
||||
@@ -32,7 +32,7 @@ describe "Editor", ->
|
||||
cachedCharWidth
|
||||
|
||||
calcDimensions = ->
|
||||
editorForMeasurement = new Editor(editSession: project.open('sample.js'))
|
||||
editorForMeasurement = new Editor(editSession: project.openSync('sample.js'))
|
||||
editorForMeasurement.attachToDom()
|
||||
cachedLineHeight = editorForMeasurement.lineHeight
|
||||
cachedCharWidth = editorForMeasurement.charWidth
|
||||
@@ -88,7 +88,7 @@ describe "Editor", ->
|
||||
it "triggers an alert", ->
|
||||
filePath = "/tmp/atom-changed-file.txt"
|
||||
fs.writeSync(filePath, "")
|
||||
editSession = project.open(filePath)
|
||||
editSession = project.openSync(filePath)
|
||||
editor.edit(editSession)
|
||||
editor.insertText("now the buffer is modified")
|
||||
|
||||
@@ -114,7 +114,7 @@ describe "Editor", ->
|
||||
[newEditSession, newBuffer] = []
|
||||
|
||||
beforeEach ->
|
||||
newEditSession = project.open('two-hundred.txt')
|
||||
newEditSession = project.openSync('two-hundred.txt')
|
||||
newBuffer = newEditSession.buffer
|
||||
|
||||
it "updates the rendered lines, cursors, selections, scroll position, and event subscriptions to match the given edit session", ->
|
||||
@@ -153,7 +153,7 @@ describe "Editor", ->
|
||||
it "triggers alert if edit session's buffer goes into conflict with changes on disk", ->
|
||||
filePath = "/tmp/atom-changed-file.txt"
|
||||
fs.writeSync(filePath, "")
|
||||
tempEditSession = project.open(filePath)
|
||||
tempEditSession = project.openSync(filePath)
|
||||
editor.edit(tempEditSession)
|
||||
tempEditSession.insertText("a buffer change")
|
||||
|
||||
@@ -262,7 +262,7 @@ describe "Editor", ->
|
||||
it "emits event when editor receives a new buffer", ->
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
editor.on 'editor:path-changed', eventHandler
|
||||
editor.edit(project.open(filePath))
|
||||
editor.edit(project.openSync(filePath))
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
it "stops listening to events on previously set buffers", ->
|
||||
@@ -270,7 +270,7 @@ describe "Editor", ->
|
||||
oldBuffer = editor.getBuffer()
|
||||
editor.on 'editor:path-changed', eventHandler
|
||||
|
||||
editor.edit(project.open(filePath))
|
||||
editor.edit(project.openSync(filePath))
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
eventHandler.reset()
|
||||
@@ -1438,7 +1438,7 @@ describe "Editor", ->
|
||||
|
||||
describe "when autoscrolling at the end of the document", ->
|
||||
it "renders lines properly", ->
|
||||
editor.edit(project.open('two-hundred.txt'))
|
||||
editor.edit(project.openSync('two-hundred.txt'))
|
||||
editor.attachToDom(heightInLines: 5.5)
|
||||
|
||||
expect(editor.renderedLines.find('.line').length).toBe 8
|
||||
@@ -1690,7 +1690,7 @@ describe "Editor", ->
|
||||
expect(editor.bufferPositionForScreenPosition(editor.getCursorScreenPosition())).toEqual [3, 60]
|
||||
|
||||
it "does not wrap the lines of any newly assigned buffers", ->
|
||||
otherEditSession = project.open()
|
||||
otherEditSession = project.openSync()
|
||||
otherEditSession.buffer.setText([1..100].join(''))
|
||||
editor.edit(otherEditSession)
|
||||
expect(editor.renderedLines.find('.line').length).toBe(1)
|
||||
@@ -1722,7 +1722,7 @@ describe "Editor", ->
|
||||
expect(editor.getCursorScreenPosition()).toEqual [11, 0]
|
||||
|
||||
it "calls .setWidthInChars() when the editor is attached because now its dimensions are available to calculate it", ->
|
||||
otherEditor = new Editor(editSession: project.open('sample.js'))
|
||||
otherEditor = new Editor(editSession: project.openSync('sample.js'))
|
||||
spyOn(otherEditor, 'setWidthInChars')
|
||||
|
||||
otherEditor.activeEditSession.setSoftWrap(true)
|
||||
@@ -1827,7 +1827,7 @@ describe "Editor", ->
|
||||
|
||||
describe "when the switching from an edit session for a long buffer to an edit session for a short buffer", ->
|
||||
it "updates the line numbers to reflect the shorter buffer", ->
|
||||
emptyEditSession = project.open(null)
|
||||
emptyEditSession = project.openSync(null)
|
||||
editor.edit(emptyEditSession)
|
||||
expect(editor.gutter.lineNumbers.find('.line-number').length).toBe 1
|
||||
|
||||
@@ -2031,7 +2031,7 @@ describe "Editor", ->
|
||||
|
||||
describe "folding", ->
|
||||
beforeEach ->
|
||||
editSession = project.open('two-hundred.txt')
|
||||
editSession = project.openSync('two-hundred.txt')
|
||||
buffer = editSession.buffer
|
||||
editor.edit(editSession)
|
||||
editor.attachToDom()
|
||||
@@ -2169,7 +2169,7 @@ describe "Editor", ->
|
||||
beforeEach ->
|
||||
filePath = project.resolve('git/working-dir/file.txt')
|
||||
originalPathText = fs.read(filePath)
|
||||
editor.edit(project.open(filePath))
|
||||
editor.edit(project.openSync(filePath))
|
||||
|
||||
afterEach ->
|
||||
fs.writeSync(filePath, originalPathText)
|
||||
@@ -2301,7 +2301,7 @@ describe "Editor", ->
|
||||
fs.remove(filePath) if fs.exists(filePath)
|
||||
|
||||
it "updates all the rendered lines when the grammar changes", ->
|
||||
editor.edit(project.open(filePath))
|
||||
editor.edit(project.openSync(filePath))
|
||||
expect(editor.getGrammar().name).toBe 'Plain Text'
|
||||
syntax.setGrammarOverrideForPath(filePath, 'source.js')
|
||||
editor.reloadGrammar()
|
||||
@@ -2321,7 +2321,7 @@ describe "Editor", ->
|
||||
expect(editor.getGrammar().name).toBe 'JavaScript'
|
||||
|
||||
it "emits an editor:grammar-changed event when updated", ->
|
||||
editor.edit(project.open(filePath))
|
||||
editor.edit(project.openSync(filePath))
|
||||
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
editor.on('editor:grammar-changed', eventHandler)
|
||||
|
||||
@@ -213,7 +213,7 @@ describe "Git", ->
|
||||
fs.writeSync(editSession.getPath(), originalContent)
|
||||
|
||||
it "emits a status-changed event", ->
|
||||
editSession = project.open('sample.js')
|
||||
editSession = project.openSync('sample.js')
|
||||
originalContent = editSession.getText()
|
||||
editSession.insertNewline()
|
||||
|
||||
@@ -230,7 +230,7 @@ describe "Git", ->
|
||||
fs.writeSync(editSession.getPath(), originalContent)
|
||||
|
||||
it "emits a status-changed event", ->
|
||||
editSession = project.open('sample.js')
|
||||
editSession = project.openSync('sample.js')
|
||||
originalContent = editSession.getText()
|
||||
fs.writeSync(editSession.getPath(), 'changed')
|
||||
|
||||
@@ -250,7 +250,7 @@ describe "Git", ->
|
||||
project2?.destroy()
|
||||
|
||||
it "subscribes to all the serialized buffers in the project", ->
|
||||
project.open('sample.js')
|
||||
project.openSync('sample.js')
|
||||
project2 = deserialize(project.serialize())
|
||||
buffer = project2.getBuffers()[0]
|
||||
originalContent = buffer.getText()
|
||||
|
||||
@@ -7,7 +7,7 @@ describe "LanguageMode", ->
|
||||
describe "javascript", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('javascript-tmbundle', sync: true)
|
||||
editSession = project.open('sample.js', autoIndent: false)
|
||||
editSession = project.openSync('sample.js', autoIndent: false)
|
||||
{buffer, languageMode} = editSession
|
||||
|
||||
describe ".minIndentLevelForRowRange(startRow, endRow)", ->
|
||||
@@ -98,7 +98,7 @@ describe "LanguageMode", ->
|
||||
describe "coffeescript", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('coffee-script-tmbundle', sync: true)
|
||||
editSession = project.open('coffee.coffee', autoIndent: false)
|
||||
editSession = project.openSync('coffee.coffee', autoIndent: false)
|
||||
{buffer, languageMode} = editSession
|
||||
|
||||
describe ".toggleLineCommentsForBufferRows(start, end)", ->
|
||||
@@ -145,7 +145,7 @@ describe "LanguageMode", ->
|
||||
describe "css", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('css-tmbundle', sync: true)
|
||||
editSession = project.open('css.css', autoIndent: false)
|
||||
editSession = project.openSync('css.css', autoIndent: false)
|
||||
{buffer, languageMode} = editSession
|
||||
|
||||
describe ".toggleLineCommentsForBufferRows(start, end)", ->
|
||||
@@ -187,7 +187,7 @@ describe "LanguageMode", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('less-tmbundle', sync: true)
|
||||
atom.activatePackage('css-tmbundle', sync: true)
|
||||
editSession = project.open('sample.less', autoIndent: false)
|
||||
editSession = project.openSync('sample.less', autoIndent: false)
|
||||
{buffer, languageMode} = editSession
|
||||
|
||||
describe "when commenting lines", ->
|
||||
@@ -198,7 +198,7 @@ describe "LanguageMode", ->
|
||||
describe "folding", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('javascript-tmbundle', sync: true)
|
||||
editSession = project.open('sample.js', autoIndent: false)
|
||||
editSession = project.openSync('sample.js', autoIndent: false)
|
||||
{buffer, languageMode} = editSession
|
||||
|
||||
it "maintains cursor buffer position when a folding/unfolding", ->
|
||||
@@ -288,7 +288,7 @@ describe "LanguageMode", ->
|
||||
describe "folding with comments", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('javascript-tmbundle', sync: true)
|
||||
editSession = project.open('sample-with-comments.js', autoIndent: false)
|
||||
editSession = project.openSync('sample-with-comments.js', autoIndent: false)
|
||||
{buffer, languageMode} = editSession
|
||||
|
||||
describe ".unfoldAll()", ->
|
||||
@@ -342,7 +342,7 @@ describe "LanguageMode", ->
|
||||
beforeEach ->
|
||||
atom.activatePackage('source-tmbundle', sync: true)
|
||||
atom.activatePackage('css-tmbundle', sync: true)
|
||||
editSession = project.open('css.css', autoIndent: true)
|
||||
editSession = project.openSync('css.css', autoIndent: true)
|
||||
|
||||
describe "suggestedIndentForBufferRow", ->
|
||||
it "does not return negative values (regression)", ->
|
||||
|
||||
@@ -96,7 +96,7 @@ describe "PaneContainer replication", ->
|
||||
# FIXME: We need to get this passing again on master
|
||||
xit "replicates splitting of panes containing edit sessions", ->
|
||||
env1.run ->
|
||||
pane1a.showItem(project.open('dir/a'))
|
||||
pane1a.showItem(project.openSync('dir/a'))
|
||||
pane1a.splitDown()
|
||||
|
||||
expect(project.getBuffers().length).toBe 1
|
||||
|
||||
@@ -109,7 +109,7 @@ describe "PaneContainer", ->
|
||||
|
||||
describe "when the last-closed pane item is an edit session", ->
|
||||
it "reopens the edit session (regression)", ->
|
||||
editSession = project.open('sample.js')
|
||||
editSession = project.openSync('sample.js')
|
||||
pane3.showItem(editSession)
|
||||
pane3.destroyItem(editSession)
|
||||
expect(container.reopenItem()).toBeTruthy()
|
||||
|
||||
@@ -7,8 +7,8 @@ describe "Pane replication", ->
|
||||
[editSession2a, editSession2b, container2, pane2, doc2] = []
|
||||
|
||||
beforeEach ->
|
||||
editSession1a = project.open('sample.js')
|
||||
editSession1b = project.open('sample.txt')
|
||||
editSession1a = project.openSync('sample.js')
|
||||
editSession1b = project.openSync('sample.txt')
|
||||
container1 = new PaneContainer
|
||||
pane1 = new Pane(editSession1a, editSession1b)
|
||||
container1.setRoot(pane1)
|
||||
@@ -24,7 +24,7 @@ describe "Pane replication", ->
|
||||
expect(pane2.items).toEqual(pane1.items)
|
||||
|
||||
it "replicates addition and removal of pane items", ->
|
||||
pane1.addItem(project.open('css.css'), 1)
|
||||
pane1.addItem(project.openSync('css.css'), 1)
|
||||
expect(pane2.items).toEqual(pane1.items)
|
||||
pane1.removeItemAtIndex(2)
|
||||
expect(pane2.items).toEqual(pane1.items)
|
||||
|
||||
@@ -19,8 +19,8 @@ describe "Pane", ->
|
||||
container = new PaneContainer
|
||||
view1 = new TestView(id: 'view-1', text: 'View 1')
|
||||
view2 = new TestView(id: 'view-2', text: 'View 2')
|
||||
editSession1 = project.open('sample.js')
|
||||
editSession2 = project.open('sample.txt')
|
||||
editSession1 = project.openSync('sample.js')
|
||||
editSession2 = project.openSync('sample.txt')
|
||||
pane = new Pane(view1, editSession1, view2, editSession2)
|
||||
container.setRoot(pane)
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ describe "Project", ->
|
||||
|
||||
describe "when an edit session 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.openSync("a")
|
||||
anotherEditSession = project.openSync("a")
|
||||
|
||||
expect(project.editSessions.length).toBe 2
|
||||
expect(editSession.buffer).toBe anotherEditSession.buffer
|
||||
@@ -41,7 +41,7 @@ describe "Project", ->
|
||||
tempFile = temp.openSync().path
|
||||
project.setPath(undefined)
|
||||
expect(project.getPath()).toBeUndefined()
|
||||
editSession = project.open()
|
||||
editSession = project.openSync()
|
||||
editSession.saveAs(tempFile)
|
||||
expect(project.getPath()).toBe path.dirname(tempFile)
|
||||
|
||||
@@ -50,7 +50,7 @@ describe "Project", ->
|
||||
handler = jasmine.createSpy('editSessionCreatedHandler')
|
||||
project.on 'edit-session-created', handler
|
||||
|
||||
editSession1 = project.open("a")
|
||||
editSession1 = project.openSync("a")
|
||||
expect(handler.callCount).toBe 1
|
||||
expect(project.getEditSessions().length).toBe 1
|
||||
expect(project.getEditSessions()[0]).toBe editSession1
|
||||
@@ -82,30 +82,30 @@ describe "Project", ->
|
||||
describe "when passed a path that doesn't match a custom opener", ->
|
||||
describe "when given an absolute path that hasn't been opened previously", ->
|
||||
it "returns a new edit session for the given path and emits 'buffer-created' and 'edit-session-created' events", ->
|
||||
editSession = project.open(absolutePath)
|
||||
editSession = project.openSync(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 'buffer-created' and 'edit-session-created' events", ->
|
||||
editSession = project.open('a')
|
||||
editSession = project.openSync('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 'edit-session-created' event", ->
|
||||
editSession = project.open(absolutePath)
|
||||
editSession = project.openSync(absolutePath)
|
||||
newBufferHandler.reset()
|
||||
expect(project.open(absolutePath).buffer).toBe editSession.buffer
|
||||
expect(project.open('a').buffer).toBe editSession.buffer
|
||||
expect(project.openSync(absolutePath).buffer).toBe editSession.buffer
|
||||
expect(project.openSync('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 'buffer-created' and 'edit-session-created' events", ->
|
||||
editSession = project.open()
|
||||
editSession = project.openSync()
|
||||
expect(editSession.buffer.getPath()).toBeUndefined()
|
||||
expect(newBufferHandler).toHaveBeenCalledWith(editSession.buffer)
|
||||
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
|
||||
@@ -113,8 +113,8 @@ describe "Project", ->
|
||||
describe "when passed a path that matches a custom opener", ->
|
||||
it "returns the resource returned by the custom opener", ->
|
||||
pathToOpen = project.resolve('a.foo')
|
||||
expect(project.open(pathToOpen, hey: "there")).toEqual { foo: pathToOpen, options: {hey: "there"} }
|
||||
expect(project.open("bar://baz")).toEqual { bar: "bar://baz" }
|
||||
expect(project.openSync(pathToOpen, hey: "there")).toEqual { foo: pathToOpen, options: {hey: "there"} }
|
||||
expect(project.openSync("bar://baz")).toEqual { bar: "bar://baz" }
|
||||
|
||||
describe ".openAsync(path)", ->
|
||||
[fooOpener, barOpener, absolutePath, newBufferHandler, newEditSessionHandler] = []
|
||||
@@ -166,8 +166,8 @@ describe "Project", ->
|
||||
|
||||
runs ->
|
||||
newBufferHandler.reset()
|
||||
expect(project.open(absolutePath).buffer).toBe editSession.buffer
|
||||
expect(project.open('a').buffer).toBe editSession.buffer
|
||||
expect(project.openSync(absolutePath).buffer).toBe editSession.buffer
|
||||
expect(project.openSync('a').buffer).toBe editSession.buffer
|
||||
expect(newBufferHandler).not.toHaveBeenCalled()
|
||||
expect(newEditSessionHandler).toHaveBeenCalledWith editSession
|
||||
|
||||
|
||||
@@ -48,10 +48,10 @@ describe "RootView", ->
|
||||
pane2 = pane1.splitRight()
|
||||
pane3 = pane2.splitRight()
|
||||
pane4 = pane2.splitDown()
|
||||
pane2.showItem(project.open('b'))
|
||||
pane3.showItem(project.open('../sample.js'))
|
||||
pane2.showItem(project.openSync('b'))
|
||||
pane3.showItem(project.openSync('../sample.js'))
|
||||
pane3.activeItem.setCursorScreenPosition([2, 4])
|
||||
pane4.showItem(project.open('../sample.txt'))
|
||||
pane4.showItem(project.openSync('../sample.txt'))
|
||||
pane4.activeItem.setCursorScreenPosition([0, 2])
|
||||
pane2.focus()
|
||||
|
||||
|
||||
@@ -447,7 +447,7 @@ describe "TextMateGrammar", ->
|
||||
|
||||
describe "when the grammar is added", ->
|
||||
it "retokenizes existing buffers that contain tokens that match the injection selector", ->
|
||||
editSession = project.open('sample.js')
|
||||
editSession = project.openSync('sample.js')
|
||||
editSession.setText("// http://github.com")
|
||||
|
||||
{tokens} = editSession.lineForScreenRow(0)
|
||||
@@ -462,7 +462,7 @@ describe "TextMateGrammar", ->
|
||||
|
||||
describe "when the grammar is updated", ->
|
||||
it "retokenizes existing buffers that contain tokens that match the injection selector", ->
|
||||
editSession = project.open('sample.js')
|
||||
editSession = project.openSync('sample.js')
|
||||
editSession.setText("// SELECT * FROM OCTOCATS")
|
||||
|
||||
{tokens} = editSession.lineForScreenRow(0)
|
||||
|
||||
@@ -191,7 +191,7 @@ class Project
|
||||
# Options that you can pass to the {EditSession} constructor
|
||||
#
|
||||
# Returns a promise that resolves to an {EditSession}.
|
||||
openAsync: (filePath, options={}) ->
|
||||
open: (filePath, options={}) ->
|
||||
filePath = @resolve(filePath)
|
||||
resource = null
|
||||
_.find @openers, (opener) -> resource = opener(filePath, options)
|
||||
@@ -200,10 +200,10 @@ class Project
|
||||
Q(resource)
|
||||
else
|
||||
@bufferForPathAsync(filePath).then (buffer) =>
|
||||
editSession = @buildEditSessionForBuffer(buffer, options)
|
||||
@buildEditSessionForBuffer(buffer, options)
|
||||
|
||||
# Private: Only be used in specs
|
||||
open: (filePath, options={}) ->
|
||||
openSync: (filePath, options={}) ->
|
||||
filePath = @resolve(filePath)
|
||||
for opener in @openers
|
||||
return resource if resource = opener(filePath, options)
|
||||
|
||||
@@ -177,20 +177,19 @@ class RootView extends View
|
||||
activePane = @getActivePane()
|
||||
|
||||
editSession = activePane.itemForUri(project.relativize(filePath)) if activePane and filePath
|
||||
promise = project.openAsync(filePath, {initialLine}) if not editSession
|
||||
promise = project.open(filePath, {initialLine}) if not editSession
|
||||
|
||||
fileSize = 0
|
||||
fileSize = fs.statSync(filePath).size if fsUtils.exists(filePath)
|
||||
|
||||
Q(editSession ? promise)
|
||||
.then (editSession) =>
|
||||
if not activePane
|
||||
activePane = new Pane(editSession)
|
||||
@panes.setRoot(activePane)
|
||||
Q(editSession ? promise).then (editSession) =>
|
||||
if not activePane
|
||||
activePane = new Pane(editSession)
|
||||
@panes.setRoot(activePane)
|
||||
|
||||
activePane.showItem(editSession)
|
||||
activePane.focus()
|
||||
editSession
|
||||
activePane.showItem(editSession)
|
||||
activePane.focus()
|
||||
editSession
|
||||
|
||||
# Private: Only used in specs
|
||||
openSync: (filePath, options = {}) ->
|
||||
@@ -199,12 +198,12 @@ class RootView extends View
|
||||
filePath = project.relativize(filePath)
|
||||
if activePane = @getActivePane()
|
||||
if filePath
|
||||
editSession = activePane.itemForUri(filePath) ? project.open(filePath, {initialLine})
|
||||
editSession = activePane.itemForUri(filePath) ? project.openSync(filePath, {initialLine})
|
||||
else
|
||||
editSession = project.open()
|
||||
editSession = project.openSync()
|
||||
activePane.showItem(editSession)
|
||||
else
|
||||
editSession = project.open(filePath, {initialLine})
|
||||
editSession = project.openSync(filePath, {initialLine})
|
||||
activePane = new Pane(editSession)
|
||||
@panes.setRoot(activePane)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user