From 9419a9ec86817753bea18f4f3f8be05cf4c38d91 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 4 Jan 2012 15:25:57 -0800 Subject: [PATCH 1/3] Spread the app specs out. --- spec/atom/app-spec.coffee | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/atom/app-spec.coffee b/spec/atom/app-spec.coffee index 44a8c4ba6..f4d27b52f 100644 --- a/spec/atom/app-spec.coffee +++ b/spec/atom/app-spec.coffee @@ -12,27 +12,29 @@ describe "App", -> describe "open", -> describe "when opening a filePath", -> - it "loads a buffer with filePath contents and displays it in a new window", -> + it "displays it in a new window", -> filePath = require.resolve 'fixtures/sample.txt' expect(app.windows().length).toBe 0 app.open filePath expect(app.windows().length).toBe 1 - newWindow = app.windows()[0] + it "loads a buffer with filePath contents", -> + filePath = require.resolve 'fixtures/sample.txt' + + app.open filePath + + newWindow = app.windows()[0] 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 "" From 3ffe57f228b7bf93bcad2be3ce303d7a8a4bf28e Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 4 Jan 2012 15:26:27 -0800 Subject: [PATCH 2/3] Project.getFilePaths returns full urls. FileFinder.initialize takes a 'selected' callback. --- spec/atom/file-finder-spec.coffee | 10 +++++++--- spec/atom/project-spec.coffee | 3 +-- spec/atom/root-view-spec.coffee | 8 -------- src/atom/file-finder.coffee | 5 ++--- src/atom/project.coffee | 3 +-- src/atom/root-view.coffee | 2 +- 6 files changed, 12 insertions(+), 19 deletions(-) diff --git a/spec/atom/file-finder-spec.coffee b/spec/atom/file-finder-spec.coffee index 1faf3181f..73fa6cd97 100644 --- a/spec/atom/file-finder-spec.coffee +++ b/spec/atom/file-finder-spec.coffee @@ -59,11 +59,15 @@ describe 'FileFinder', -> expect(finder.find('li:last')).toHaveClass "selected" describe "select", -> - it "when an file is selected atom.open is called", -> - spyOn(atom, 'open') + selectedCallback = jasmine.createSpy 'selected' + + beforeEach -> + finder = FileFinder.build {urls, selected: selectedCallback} + + it "when a file is selected Editor.open is called", -> finder.moveDown() finder.select() - expect(atom.open).toHaveBeenCalledWith(urls[1]) + expect(selectedCallback).toHaveBeenCalledWith(urls[1]) it "when no file is selected, does nothing", -> spyOn(atom, 'open') diff --git a/spec/atom/project-spec.coffee b/spec/atom/project-spec.coffee index 8c5665ef2..39f6517a6 100644 --- a/spec/atom/project-spec.coffee +++ b/spec/atom/project-spec.coffee @@ -8,8 +8,7 @@ describe "Project", -> describe ".getFilePaths()", -> it "returns a promise which resolves to a list of all file urls in the project, recursively", -> - expectedPaths = for url in fs.list(project.url, true) when fs.isFile url - url.replace project.url, '' + expectedPaths = (url for url in fs.list(project.url, true) when fs.isFile url) waitsForPromise -> project.getFilePaths().done (result) -> diff --git a/spec/atom/root-view-spec.coffee b/spec/atom/root-view-spec.coffee index 706865e7e..84d8de2af 100644 --- a/spec/atom/root-view-spec.coffee +++ b/spec/atom/root-view-spec.coffee @@ -55,14 +55,6 @@ describe "RootView", -> runs -> expect(rootView.fileFinder.urlList.children('li').length).toBe 3 - it "removes common path prefix from files", -> - waitsForPromise -> - rootView.toggleFileFinder() - - runs -> - commonPathPattern = new RegExp("^" + fs.directory(url)) - expect(rootView.fileFinder.urlList.children('li:first').text()).not.toMatch commonPathPattern - describe "when there is no project", -> beforeEach -> rootView = RootView.build() diff --git a/src/atom/file-finder.coffee b/src/atom/file-finder.coffee index 4d3a4c9dd..cdad3bf00 100644 --- a/src/atom/file-finder.coffee +++ b/src/atom/file-finder.coffee @@ -14,7 +14,7 @@ class FileFinder extends Template urls: null maxResults: null - initialize: ({@urls}) -> + initialize: ({@urls, @selected}) -> @maxResults = 10 @populateUrlList() @@ -34,8 +34,7 @@ class FileFinder extends Template select: -> filePath = @findSelectedLi().text() - atom.open filePath if filePath - + @selected(filePath) if filePath and @selected moveUp: -> @findSelectedLi() diff --git a/src/atom/project.coffee b/src/atom/project.coffee index 87c501104..9ed505636 100644 --- a/src/atom/project.coffee +++ b/src/atom/project.coffee @@ -8,6 +8,5 @@ class Project getFilePaths: -> projectUrl = @url fs.async.list(@url, true).pipe (urls) -> - urls = (url.replace(projectUrl, "") for url in urls when fs.isFile(url)) - urls + url for url in urls when fs.isFile(url) diff --git a/src/atom/root-view.coffee b/src/atom/root-view.coffee index e198fd174..17560521b 100644 --- a/src/atom/root-view.coffee +++ b/src/atom/root-view.coffee @@ -43,6 +43,6 @@ class RootView extends Template @fileFinder = null else @project.getFilePaths().done (urls) => - @fileFinder = FileFinder.build({urls}) + @fileFinder = FileFinder.build({urls, selected: (url) => @editor.open(url)}) @addPane(@fileFinder) @fileFinder.input.focus() From 7e270d641d6a1663987bb60e6998413f32f0e097 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 4 Jan 2012 15:47:41 -0800 Subject: [PATCH 3/3] FileFinder removes itself when item is selected. --- spec/atom/file-finder-spec.coffee | 2 ++ src/atom/file-finder.coffee | 1 + src/atom/root-view.coffee | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/atom/file-finder-spec.coffee b/spec/atom/file-finder-spec.coffee index 73fa6cd97..91cb703e9 100644 --- a/spec/atom/file-finder-spec.coffee +++ b/spec/atom/file-finder-spec.coffee @@ -65,9 +65,11 @@ describe 'FileFinder', -> finder = FileFinder.build {urls, selected: selectedCallback} it "when a file is selected Editor.open is called", -> + spyOn(finder, 'remove') finder.moveDown() finder.select() expect(selectedCallback).toHaveBeenCalledWith(urls[1]) + expect(finder.remove).toHaveBeenCalled() it "when no file is selected, does nothing", -> spyOn(atom, 'open') diff --git a/src/atom/file-finder.coffee b/src/atom/file-finder.coffee index cdad3bf00..8c980ec8e 100644 --- a/src/atom/file-finder.coffee +++ b/src/atom/file-finder.coffee @@ -35,6 +35,7 @@ class FileFinder extends Template select: -> filePath = @findSelectedLi().text() @selected(filePath) if filePath and @selected + @remove() moveUp: -> @findSelectedLi() diff --git a/src/atom/root-view.coffee b/src/atom/root-view.coffee index 17560521b..d76449502 100644 --- a/src/atom/root-view.coffee +++ b/src/atom/root-view.coffee @@ -38,7 +38,7 @@ class RootView extends Template toggleFileFinder: -> return unless @project - if @fileFinder + if @fileFinder and @fileFinder.parent()[0] @fileFinder.remove() @fileFinder = null else