Sort buffers by most recently opened

This commit is contained in:
Chris Wanstrath
2013-02-11 13:20:31 -08:00
parent b2a9208acf
commit bb0a19fba3
2 changed files with 34 additions and 4 deletions

View File

@@ -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: ->

View File

@@ -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", ->