Display error if no files match word under cursor

This commit is contained in:
Corey Johnson
2013-01-21 15:01:44 -08:00
parent 0a5e0a85f8
commit ad8a29df80
2 changed files with 38 additions and 6 deletions

View File

@@ -304,6 +304,31 @@ describe 'FuzzyFinder', ->
expect(finder).not.toBeVisible()
expect(openedPath).toBe "sample.txt"
it "displays error when the word under the cursor doesn't match any files", ->
editor.setText("moogoogaipan")
editor.setCursorBufferPosition([0,5])
rootView.trigger 'fuzzy-finder:find-under-cursor'
waitsFor ->
finder.is(':visible')
runs ->
expect(finder.find('.error').text().length).toBeGreaterThan 0
it "displays error when there is no word under the cursor", ->
editor.setText("&&&&&&&&&&&&&&& sample")
editor.setCursorBufferPosition([0,5])
rootView.trigger 'fuzzy-finder:find-under-cursor'
waitsFor ->
finder.is(':visible')
runs ->
expect(finder.find('.error').text().length).toBeGreaterThan 0
describe "opening a path into a split", ->
beforeEach ->
rootView.attachToDom()

View File

@@ -105,13 +105,20 @@ class FuzzyFinder extends SelectList
editor = @rootView.getActiveEditor()
range = editor.getCursor().getCurrentWordBufferRange(wordRegex: @filenameRegex)
currentWord = editor.getTextInRange(range)
if currentWord?
@populateProjectPaths(filter: currentWord, done: (paths) =>
if paths?.length == 1
@rootView.open(paths[0])
else if paths?.length
if currentWord.length == 0
@attach()
@setError('The cursor is not over a filename')
else
@populateProjectPaths filter: currentWord, done: (paths) =>
if paths.length == 0
@attach()
@miniEditor.setText('' + currentWord))
@setError('No files match \'currentWord\'')
else if paths.length == 1
@rootView.open(paths[0])
else
@attach()
@miniEditor.setText(currentWord)
populateProjectPaths: (options = {}) ->
if @projectPaths?.length > 0