Display relative paths in the file finder

This commit is contained in:
Corey Johnson
2012-01-05 11:01:17 -08:00
parent 192166d61a
commit 4121b2076e
2 changed files with 25 additions and 5 deletions

View File

@@ -4,11 +4,13 @@ RootView = require 'root-view'
describe "RootView", ->
rootView = null
project = null
url = null
beforeEach ->
url = require.resolve 'fixtures/dir/a'
rootView = RootView.build {url}
project = rootView.project
describe "initialize", ->
describe "when called with a url that references a file", ->
@@ -49,11 +51,17 @@ describe "RootView", ->
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).not.toExist()
it "shows all urls for the current project", ->
fit "shows all relative file paths for the current project", ->
waitsForPromise ->
rootView.toggleFileFinder()
runs ->
expect(rootView.fileFinder.urlList.children('li').length).toBe 3
waitsForPromise ->
project.getFilePaths().done (paths) ->
expect(rootView.fileFinder.urlList.children('li').length).toBe paths.length
for path in paths
relativePath = path.replace(project.url, '')
expect(rootView.fileFinder.urlList.find("li:contains(#{relativePath}):not(:contains(#{project.url}))")).toExist()
describe "when there is no project", ->
beforeEach ->
@@ -65,3 +73,14 @@ describe "RootView", ->
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).not.toExist()
fdescribe "when a path is selected in the file finder", ->
it "opens the file associated with that path in the editor", ->
waitsForPromise -> rootView.toggleFileFinder()
runs ->
firstLi = rootView.fileFinder.find('li:first')
rootView.fileFinder.select()
expect(rootView.editor.buffer.url).toBe(project.url + firstLi.text())

View File

@@ -37,7 +37,8 @@ class RootView extends Template
@fileFinder.remove()
@fileFinder = null
else
@project.getFilePaths().done (urls) =>
@fileFinder = FileFinder.build({urls, selected: (url) => @editor.open(url)})
@project.getFilePaths().done (paths) =>
relativePaths = (path.replace(@project.url, "") for path in paths)
@fileFinder = FileFinder.build({urls: relativePaths, selected: (relativePath) => @editor.open(@project.url + relativePath)})
@addPane(@fileFinder)
@fileFinder.input.focus()