mirror of
https://github.com/atom/atom.git
synced 2026-02-18 18:34:21 -05:00
Merge branch 'dev' into css-theme-refactor
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
'body':
|
||||
'meta-t': 'fuzzy-finder:toggle-file-finder'
|
||||
'meta-b': 'fuzzy-finder:toggle-buffer-finder'
|
||||
'ctrl-.': 'fuzzy-finder:find-under-cursor'
|
||||
|
||||
@@ -270,6 +270,65 @@ describe 'FuzzyFinder', ->
|
||||
runs ->
|
||||
expect(finder.list.find("li:contains(tree-view.js)")).not.toExist()
|
||||
|
||||
describe "fuzzy find by content under cursor", ->
|
||||
editor = null
|
||||
|
||||
beforeEach ->
|
||||
editor = rootView.getActiveEditor()
|
||||
rootView.attachToDom()
|
||||
spyOn(rootView.project, "getFilePaths").andCallThrough()
|
||||
|
||||
it "opens the fuzzy finder window when there are multiple matches", ->
|
||||
editor.setText("sample")
|
||||
rootView.trigger 'fuzzy-finder:find-under-cursor'
|
||||
|
||||
waitsFor ->
|
||||
finder.list.children('li').length > 0
|
||||
|
||||
runs ->
|
||||
expect(finder).toBeVisible()
|
||||
expect(rootView.find('.fuzzy-finder input:focus')).toExist()
|
||||
|
||||
it "opens a file directly when there is a single match", ->
|
||||
editor.setText("sample.txt")
|
||||
rootView.trigger 'fuzzy-finder:find-under-cursor'
|
||||
|
||||
openedPath = null
|
||||
spyOn(rootView, "open").andCallFake (path) ->
|
||||
openedPath = path
|
||||
|
||||
waitsFor ->
|
||||
openedPath != null
|
||||
|
||||
runs ->
|
||||
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()
|
||||
|
||||
@@ -6,10 +6,13 @@ fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class FuzzyFinder extends SelectList
|
||||
filenameRegex: /[\w\.\-\/\\]+/
|
||||
|
||||
@activate: (rootView) ->
|
||||
@instance = new FuzzyFinder(rootView)
|
||||
rootView.command 'fuzzy-finder:toggle-file-finder', => @instance.toggleFileFinder()
|
||||
rootView.command 'fuzzy-finder:toggle-buffer-finder', => @instance.toggleBufferFinder()
|
||||
rootView.command 'fuzzy-finder:find-under-cursor', => @instance.findUnderCursor()
|
||||
|
||||
@viewClass: ->
|
||||
[super, 'fuzzy-finder'].join(' ')
|
||||
@@ -93,9 +96,39 @@ class FuzzyFinder extends SelectList
|
||||
@populateOpenBufferPaths()
|
||||
@attach() if @paths?.length
|
||||
|
||||
populateProjectPaths: ->
|
||||
findUnderCursor: ->
|
||||
if @hasParent()
|
||||
@cancel()
|
||||
else
|
||||
return unless @rootView.project.getPath()?
|
||||
@allowActiveEditorChange = false
|
||||
editor = @rootView.getActiveEditor()
|
||||
currentWord = editor.getWordUnderCursor(wordRegex: @filenameRegex)
|
||||
|
||||
if currentWord.length == 0
|
||||
@attach()
|
||||
@setError("The cursor is not over a filename")
|
||||
else
|
||||
@populateProjectPaths filter: currentWord, done: (paths) =>
|
||||
if paths.length == 0
|
||||
@attach()
|
||||
@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
|
||||
@setArray(@projectPaths)
|
||||
listedItems =
|
||||
if options.filter?
|
||||
@projectPaths.filter (path) ->
|
||||
path.indexOf(options.filter) >= 0
|
||||
else
|
||||
@projectPaths
|
||||
@setArray(listedItems)
|
||||
options.done(listedItems) if options.done?
|
||||
else
|
||||
@setLoading("Indexing...")
|
||||
|
||||
@@ -111,7 +144,15 @@ class FuzzyFinder extends SelectList
|
||||
return true
|
||||
|
||||
@reloadProjectPaths = false
|
||||
@setArray(@projectPaths)
|
||||
listedItems =
|
||||
if options.filter?
|
||||
@projectPaths.filter (path) ->
|
||||
path.indexOf(options.filter) >= 0
|
||||
else
|
||||
@projectPaths
|
||||
|
||||
@setArray(listedItems)
|
||||
options.done(listedItems) if options.done?
|
||||
|
||||
populateOpenBufferPaths: ->
|
||||
@paths = @rootView.getOpenBufferPaths().map (path) =>
|
||||
|
||||
@@ -183,7 +183,7 @@ class TreeView extends ScrollView
|
||||
if selectedEntry
|
||||
if selectedEntry.is('.expanded.directory')
|
||||
return if @selectEntry(selectedEntry.find('.entry:first'))
|
||||
until @selectEntry(selectedEntry.next())
|
||||
until @selectEntry(selectedEntry.next('.entry'))
|
||||
selectedEntry = selectedEntry.parents('.entry:first')
|
||||
break unless selectedEntry.length
|
||||
else
|
||||
@@ -194,7 +194,7 @@ class TreeView extends ScrollView
|
||||
moveUp: ->
|
||||
selectedEntry = @selectedEntry()
|
||||
if selectedEntry
|
||||
if previousEntry = @selectEntry(selectedEntry.prev())
|
||||
if previousEntry = @selectEntry(selectedEntry.prev('.entry'))
|
||||
if previousEntry.is('.expanded.directory')
|
||||
@selectEntry(previousEntry.find('.entry:last'))
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user