Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Current opened files on top of list
Browse files Browse the repository at this point in the history
  • Loading branch information
lasekio committed Nov 6, 2015
1 parent 90e1097 commit 7f08fcf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
33 changes: 12 additions & 21 deletions lib/project-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,23 @@ class ProjectView extends FuzzyFinderView
@loadingBadge.text(humanize.intComma(pathsFound))

projectRelativePathsForFilePaths: ->
projectRelativePaths = super
@getLastOpenedPaths().concat super

if lastOpenedPath = @getLastOpenedPath()
for {filePath}, index in projectRelativePaths
if filePath is lastOpenedPath
[entry] = projectRelativePaths.splice(index, 1)
projectRelativePaths.unshift(entry)
break
getLastOpenedPaths: ->
activePath = atom.workspace.getActivePaneItem()?.getPath?()
editors = atom.workspace.getTextEditors()

projectRelativePaths
recentEditors = editors.filter (editor) -> activePath != editor.getPath()

getLastOpenedPath: ->
activePath = atom.workspace.getActivePaneItem()?.getPath?()
recentEditors.sort (editorA, editorB) ->
editorB.lastOpened - editorA.lastOpened

lastOpenedEditor = null
paths = recentEditors.map (editor) ->
filePath = editor.getPath()
[rootPath, projectRelativePath] = atom.project.relativizePath(filePath)
{ filePath, projectRelativePath }

for editor in atom.workspace.getTextEditors()
filePath = editor.getPath()
continue unless filePath
continue if activePath is filePath

lastOpenedEditor ?= editor
if editor.lastOpened > lastOpenedEditor.lastOpened
lastOpenedEditor = editor

lastOpenedEditor?.getPath()
paths

destroy: ->
@loadPathsTask?.terminate()
Expand Down
4 changes: 3 additions & 1 deletion spec/fuzzy-finder-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ describe 'FuzzyFinder', ->
expect(PathLoader.startTask.callCount).toBe 1

it "puts the last active path first", ->
waitsForPromise -> atom.workspace.open 'dir/a'
waitsForPromise -> atom.workspace.open 'sample.txt'
waitsForPromise -> atom.workspace.open 'sample.js'

Expand All @@ -139,7 +140,8 @@ describe 'FuzzyFinder', ->

runs ->
expect(projectView.list.find("li:eq(0)").text()).toContain('sample.txt')
expect(projectView.list.find("li:eq(1)").text()).toContain('sample.html')
expect(projectView.list.find("li:eq(1)").text()).toContain('dir/a')
expect(projectView.list.find("li:eq(2)").text()).toContain('sample.html')

describe "symlinks on #darwin or #linux", ->
[junkDirPath, junkFilePath] = []
Expand Down

0 comments on commit 7f08fcf

Please sign in to comment.