Serialize buffer last opened times in fuzzy-finder

This commit is contained in:
Chris Wanstrath
2013-02-12 22:32:05 -08:00
parent 8714983411
commit 2dc6dfc39f
3 changed files with 33 additions and 1 deletions

View File

@@ -160,6 +160,12 @@ class FuzzyFinderView extends SelectList
@setArray(@paths)
getPaths: ->
paths = {}
for editSession in rootView.project.getEditSessions()
paths[editSession.getPath()] = editSession.lastOpened
paths
detach: ->
super

View File

@@ -1,8 +1,10 @@
_ = require 'underscore'
module.exports =
projectPaths: null
fuzzyFinderView: null
activate: ->
activate: (state) ->
rootView.command 'fuzzy-finder:toggle-file-finder', =>
@createView().toggleFileFinder()
rootView.command 'fuzzy-finder:toggle-buffer-finder', =>
@@ -15,6 +17,11 @@ module.exports =
@loadPathsTask = new LoadPathsTask((paths) => @projectPaths = paths)
@loadPathsTask.start()
for path, lastOpened of state
session = _.detect rootView.project.getEditSessions(), (editSession) ->
editSession.getPath() is path
session?.lastOpened = lastOpened
deactivate: ->
@loadPathsTask?.terminate()
@fuzzyFinderView?.cancel()
@@ -22,6 +29,9 @@ module.exports =
@projectPaths = null
@fuzzyFinderView = null
serialize: ->
@fuzzyFinderView?.getPaths()
createView: ->
unless @fuzzyFinderView
FuzzyFinderView = require 'fuzzy-finder/lib/fuzzy-finder-view'

View File

@@ -1,6 +1,7 @@
RootView = require 'root-view'
FuzzyFinder = require 'fuzzy-finder/lib/fuzzy-finder-view'
LoadPathsTask = require 'fuzzy-finder/lib/load-paths-task'
_ = require 'underscore'
$ = require 'jquery'
{$$} = require 'space-pen'
fs = require 'fs'
@@ -145,6 +146,21 @@ describe 'FuzzyFinder', ->
expect(finderView.list.find("li:contains(sample-with-tabs.coffee)")).toExist()
expect(finderView.list.children().first()).toHaveClass 'selected'
it "serializes the list of paths and their last opened time", ->
rootView.open 'sample-with-tabs.coffee'
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
rootView.open 'sample.js'
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
states = rootView.serialize().packageStates
states = _.map states['fuzzy-finder'], (path, time) -> [ path, time ]
states = _.sortBy states, (path, time) -> -time
paths = [ 'sample-with-tabs.coffee', 'sample.txt', 'sample.js' ]
for [time, path] in states
expect(_.last path.split '/').toBe paths.shift()
expect(time).toBeGreaterThan 50000
describe "when the active editor only contains edit sessions for anonymous buffers", ->
it "does not open", ->
editor = rootView.getActiveEditor()