Run fuzzy filter on project relative paths

This prevents the score being influenced by the
segments contained in the project path.

Closes #553
This commit is contained in:
Kevin Sawicki
2013-05-16 08:47:21 -07:00
parent 04d4085759
commit 95d4391680
2 changed files with 21 additions and 12 deletions

View File

@@ -16,6 +16,7 @@ class FuzzyFinderView extends SelectList
maxItems: 10
projectPaths: null
reloadProjectPaths: true
filterKey: 'projectRelativePath'
initialize: ->
super
@@ -35,7 +36,7 @@ class FuzzyFinderView extends SelectList
@miniEditor.command 'pane:split-up', =>
@splitOpenPath (pane, session) -> pane.splitUp(session)
itemForElement: (path) ->
itemForElement: ({path, projectRelativePath}) ->
$$ ->
@li class: 'two-lines', =>
if git?
@@ -60,20 +61,20 @@ class FuzzyFinderView extends SelectList
typeClass = 'text-name'
@div fsUtils.base(path), class: "primary-line file #{typeClass}"
@div project.relativize(path), class: 'secondary-line path'
@div projectRelativePath, class: 'secondary-line path'
openPath: (path) ->
rootView.open(path, {@allowActiveEditorChange}) if path
splitOpenPath: (fn) ->
path = @getSelectedElement()
{path} = @getSelectedElement()
return unless path
if pane = rootView.getActivePane()
fn(pane, project.open(path))
else
@openPath(path)
confirmed : (path) ->
confirmed : ({path}) ->
return unless path.length
if fsUtils.isFile(path)
@cancel()
@@ -131,6 +132,14 @@ class FuzzyFinderView extends SelectList
@attach()
@miniEditor.setText(currentWord)
setArray: (paths) ->
projectRelativePaths = []
for path in paths
projectRelativePath = project.relativize(path)
projectRelativePaths.push({path, projectRelativePath})
super(projectRelativePaths)
populateGitStatusPaths: ->
paths = []
paths.push(path) for path, status of git.statuses when fsUtils.isFile(path)

View File

@@ -100,7 +100,7 @@ describe 'FuzzyFinder', ->
rootView.trigger 'fuzzy-finder:toggle-file-finder'
expectedPath = project.resolve('dir/a')
finderView.confirmed(expectedPath)
finderView.confirmed({path: expectedPath})
expect(finderView.hasParent()).toBeFalsy()
expect(editor1.getPath()).not.toBe expectedPath
@@ -112,7 +112,7 @@ describe 'FuzzyFinder', ->
rootView.attachToDom()
path = rootView.getActiveView().getPath()
rootView.trigger 'fuzzy-finder:toggle-file-finder'
finderView.confirmed('dir/this/is/not/a/file.txt')
finderView.confirmed({path: 'dir/this/is/not/a/file.txt'})
expect(finderView.hasParent()).toBeTruthy()
expect(rootView.getActiveView().getPath()).toBe path
expect(finderView.find('.error').text().length).toBeGreaterThan 0
@@ -210,7 +210,7 @@ describe 'FuzzyFinder', ->
describe "when the active pane has an item for the selected path", ->
it "switches to the item for the selected path", ->
expectedPath = project.resolve('sample.txt')
finderView.confirmed(expectedPath)
finderView.confirmed({path: expectedPath})
expect(finderView.hasParent()).toBeFalsy()
expect(editor1.getPath()).not.toBe expectedPath
@@ -226,7 +226,7 @@ describe 'FuzzyFinder', ->
expect(rootView.getActiveView()).toBe editor1
expectedPath = project.resolve('sample.txt')
finderView.confirmed(expectedPath)
finderView.confirmed({path: expectedPath})
expect(finderView.hasParent()).toBeFalsy()
expect(editor1.getPath()).toBe expectedPath
@@ -449,7 +449,7 @@ describe 'FuzzyFinder', ->
spyOn(pane, "splitLeft").andCallThrough()
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
path = finderView.getSelectedElement()
{path} = finderView.getSelectedElement()
finderView.miniEditor.trigger 'pane:split-left'
expect(rootView.getPanes().length).toBe 2
@@ -462,7 +462,7 @@ describe 'FuzzyFinder', ->
spyOn(pane, "splitRight").andCallThrough()
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
path = finderView.getSelectedElement()
{path} = finderView.getSelectedElement()
finderView.miniEditor.trigger 'pane:split-right'
expect(rootView.getPanes().length).toBe 2
@@ -475,7 +475,7 @@ describe 'FuzzyFinder', ->
spyOn(pane, "splitUp").andCallThrough()
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
path = finderView.getSelectedElement()
{path} = finderView.getSelectedElement()
finderView.miniEditor.trigger 'pane:split-up'
expect(rootView.getPanes().length).toBe 2
@@ -488,7 +488,7 @@ describe 'FuzzyFinder', ->
spyOn(pane, "splitDown").andCallThrough()
rootView.trigger 'fuzzy-finder:toggle-buffer-finder'
path = finderView.getSelectedElement()
{path} = finderView.getSelectedElement()
finderView.miniEditor.trigger 'pane:split-down'
expect(rootView.getPanes().length).toBe 2