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

Commit f9d36ed

Browse files
committed
Current opened files on top of list
1 parent 90e1097 commit f9d36ed

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

lib/project-view.coffee

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,23 @@ class ProjectView extends FuzzyFinderView
8787
@loadingBadge.text(humanize.intComma(pathsFound))
8888

8989
projectRelativePathsForFilePaths: ->
90-
projectRelativePaths = super
90+
@getLastOpenedPaths().concat super
9191

92-
if lastOpenedPath = @getLastOpenedPath()
93-
for {filePath}, index in projectRelativePaths
94-
if filePath is lastOpenedPath
95-
[entry] = projectRelativePaths.splice(index, 1)
96-
projectRelativePaths.unshift(entry)
97-
break
98-
99-
projectRelativePaths
100-
101-
getLastOpenedPath: ->
92+
getLastOpenedPaths: ->
10293
activePath = atom.workspace.getActivePaneItem()?.getPath?()
94+
editors = atom.workspace.getTextEditors()
10395

104-
lastOpenedEditor = null
96+
recentEditors = editors.filter (editor) -> activePath isnt editor.getPath()
10597

106-
for editor in atom.workspace.getTextEditors()
107-
filePath = editor.getPath()
108-
continue unless filePath
109-
continue if activePath is filePath
98+
recentEditors.sort (editorA, editorB) ->
99+
editorB.lastOpened - editorA.lastOpened
110100

111-
lastOpenedEditor ?= editor
112-
if editor.lastOpened > lastOpenedEditor.lastOpened
113-
lastOpenedEditor = editor
101+
paths = recentEditors.map (editor) ->
102+
filePath = editor.getPath()
103+
[rootPath, projectRelativePath] = atom.project.relativizePath(filePath)
104+
{filePath, projectRelativePath}
114105

115-
lastOpenedEditor?.getPath()
106+
paths
116107

117108
destroy: ->
118109
@loadPathsTask?.terminate()

spec/fuzzy-finder-spec.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ describe 'FuzzyFinder', ->
130130
expect(PathLoader.startTask.callCount).toBe 1
131131

132132
it "puts the last active path first", ->
133+
waitsForPromise -> atom.workspace.open 'dir/a'
133134
waitsForPromise -> atom.workspace.open 'sample.txt'
134135
waitsForPromise -> atom.workspace.open 'sample.js'
135136

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

140141
runs ->
141142
expect(projectView.list.find("li:eq(0)").text()).toContain('sample.txt')
142-
expect(projectView.list.find("li:eq(1)").text()).toContain('sample.html')
143+
expect(projectView.list.find("li:eq(1)").text()).toContain('dir/a')
144+
expect(projectView.list.find("li:eq(2)").text()).toContain('sample.html')
143145

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

0 commit comments

Comments
 (0)