mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
RootView handles opening directories
This commit is contained in:
parent
9fde405ebe
commit
236ea5e906
@ -11,14 +11,28 @@ describe "App", ->
|
||||
window.close() for window in app.windows()
|
||||
|
||||
describe "open", ->
|
||||
it "loads a buffer based on the given path and displays it in a new window", ->
|
||||
filePath = require.resolve 'fixtures/sample.txt'
|
||||
expect(app.windows().length).toBe 0
|
||||
describe "when opening a filePath", ->
|
||||
it "loads a buffer with filePath contents and displays it in a new window", ->
|
||||
filePath = require.resolve 'fixtures/sample.txt'
|
||||
expect(app.windows().length).toBe 0
|
||||
|
||||
app.open filePath
|
||||
app.open filePath
|
||||
|
||||
expect(app.windows().length).toBe 1
|
||||
newWindow = app.windows()[0]
|
||||
expect(app.windows().length).toBe 1
|
||||
newWindow = app.windows()[0]
|
||||
|
||||
expect(newWindow.rootView.editor.buffer.url).toEqual filePath
|
||||
expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath)
|
||||
expect(newWindow.rootView.editor.buffer.url).toEqual filePath
|
||||
expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath)
|
||||
|
||||
describe "when opening a dirPath", ->
|
||||
it "loads an empty buffer", ->
|
||||
dirPath = require.resolve 'fixtures'
|
||||
expect(app.windows().length).toBe 0
|
||||
|
||||
app.open dirPath
|
||||
|
||||
expect(app.windows().length).toBe 1
|
||||
newWindow = app.windows()[0]
|
||||
|
||||
expect(newWindow.rootView.editor.buffer.url).toBeUndefined
|
||||
expect(newWindow.rootView.editor.buffer.getText()).toBe ""
|
||||
|
@ -11,11 +11,18 @@ describe "RootView", ->
|
||||
rootView = RootView.build {url}
|
||||
|
||||
describe "initialize", ->
|
||||
describe "when called with a url", ->
|
||||
describe "when the url references a file", ->
|
||||
it "creates a project for the file's parent directory and opens it in the editor", ->
|
||||
expect(rootView.project.url).toBe fs.directory(url)
|
||||
expect(rootView.editor.buffer.url).toBe url
|
||||
describe "when called with a url that references a file", ->
|
||||
it "creates a project for the file's parent directory and opens it in the editor", ->
|
||||
expect(rootView.project.url).toBe fs.directory(url)
|
||||
expect(rootView.editor.buffer.url).toBe url
|
||||
|
||||
describe "when called with a url that references a directory", ->
|
||||
it "creates a project for the directory and opens and empty buffer", ->
|
||||
url = require.resolve 'fixtures/dir'
|
||||
rootView = RootView.build {url}
|
||||
|
||||
expect(rootView.project.url).toBe url
|
||||
expect(rootView.editor.buffer.url).toBeUndefined()
|
||||
|
||||
describe "when not called with a url", ->
|
||||
it "opens an empty buffer", ->
|
||||
|
@ -21,8 +21,14 @@ class RootView extends Template
|
||||
@bindKey 'meta+w', => window.close()
|
||||
@bindKey 'meta+t', => @toggleFileFinder()
|
||||
|
||||
@project = new Project(fs.directory(url)) if url
|
||||
@editor.open url
|
||||
if not url
|
||||
# not sure what to do
|
||||
else if fs.isDirectory url
|
||||
@project = new Project url
|
||||
@editor.open()
|
||||
else
|
||||
@project = new Project(fs.directory(url))
|
||||
@editor.open url
|
||||
|
||||
addPane: (view) ->
|
||||
pane = $('<div class="pane">')
|
||||
|
Loading…
Reference in New Issue
Block a user