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

Current opened files on top of list #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 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

projectRelativePaths

getLastOpenedPath: ->
getLastOpenedPaths: ->
activePath = atom.workspace.getActivePaneItem()?.getPath?()
editors = atom.workspace.getTextEditors()

lastOpenedEditor = null
recentEditors = editors.filter (editor) -> activePath isnt editor.getPath()

for editor in atom.workspace.getTextEditors()
filePath = editor.getPath()
continue unless filePath
continue if activePath is filePath
recentEditors.sort (editorA, editorB) ->
editorB.lastOpened - editorA.lastOpened

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

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