diff --git a/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee b/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee index 8b5228571..fb8da7d4f 100644 --- a/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee +++ b/src/packages/fuzzy-finder/lib/fuzzy-finder-view.coffee @@ -22,6 +22,10 @@ class FuzzyFinderView extends SelectList @subscribe $(window), 'focus', => @reloadProjectPaths = true @observeConfig 'fuzzy-finder.ignoredNames', => @reloadProjectPaths = true + rootView.eachEditor (editor) -> + editor.activeEditSession.lastOpened = (new Date) - 1 + editor.on 'editor:active-edit-session-changed', (e, editSession, index) -> + editSession.lastOpened = (new Date) - 1 @miniEditor.command 'editor:split-left', => @splitOpenPath (editor, session) -> editor.splitLeft(session) @@ -143,8 +147,19 @@ class FuzzyFinderView extends SelectList @loadPathsTask.start() populateOpenBufferPaths: -> - @paths = rootView.getOpenBufferPaths().map (path) => - rootView.project.relativize(path) + editSessions = [] + rootView.eachEditSession (editSession) -> + editSessions.push editSession + + editSessions = _.sortBy editSessions, (editSession) => + if editSession is rootView.getActiveEditSession() + 0 + else + -(editSession.lastOpened or 1) + + @paths = _.map editSessions, (editSession) => + rootView.project.relativize editSession.buffer.getPath() + @setArray(@paths) detach: -> diff --git a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee index b044cdcef..31018c362 100644 --- a/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee +++ b/src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee @@ -123,11 +123,26 @@ describe 'FuzzyFinder', -> rootView.trigger 'fuzzy-finder:toggle-buffer-finder' expect(finderView.miniEditor.getText()).toBe '' - it "lists the paths of the current open buffers", -> + it "lists the paths of the current open buffers by most recently modified", -> + rootView.attachToDom() + rootView.open 'sample-with-tabs.coffee' rootView.trigger 'fuzzy-finder:toggle-buffer-finder' - expect(finderView.list.children('li').length).toBe 2 + children = finderView.list.children('li') + expect(children.get(0).outerText).toBe "sample.txt" + expect(children.get(1).outerText).toBe "sample.js" + expect(children.get(2).outerText).toBe "sample-with-tabs.coffee" + + rootView.open 'sample.txt' + rootView.trigger 'fuzzy-finder:toggle-buffer-finder' + children = finderView.list.children('li') + expect(children.get(0).outerText).toBe "sample-with-tabs.coffee" + expect(children.get(1).outerText).toBe "sample.js" + expect(children.get(2).outerText).toBe "sample.txt" + + expect(finderView.list.children('li').length).toBe 3 expect(finderView.list.find("li:contains(sample.js)")).toExist() expect(finderView.list.find("li:contains(sample.txt)")).toExist() + expect(finderView.list.find("li:contains(sample-with-tabs.coffee)")).toExist() expect(finderView.list.children().first()).toHaveClass 'selected' describe "when the active editor only contains edit sessions for anonymous buffers", ->