mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
FileFinder loads files from editor.url's directory
This commit is contained in:
@@ -20,9 +20,8 @@ describe "Editor", ->
|
||||
editor.destroy()
|
||||
|
||||
describe "initialize", ->
|
||||
it "opens the given url", ->
|
||||
Editor.build(url: tempFilePath)
|
||||
expect(Editor.prototype.viewProperties.open).toHaveBeenCalledWith(tempFilePath)
|
||||
it "has a buffer", ->
|
||||
expect(editor.buffer).toBeDefined()
|
||||
|
||||
describe 'destroy', ->
|
||||
it 'destroys the ace editor', ->
|
||||
@@ -46,10 +45,6 @@ describe "Editor", ->
|
||||
editor.open('something.text')
|
||||
expect(editor.getAceSession().getMode().name).toBe 'text'
|
||||
|
||||
it "assigns the url on the $atomController global", ->
|
||||
editor.open("/other/path")
|
||||
expect($atomController.url.toString()).toEqual("/other/path")
|
||||
|
||||
describe "when called with null", ->
|
||||
it "loads an empty buffer with no url", ->
|
||||
editor.open()
|
||||
|
||||
@@ -2,15 +2,18 @@ FileFinder = require 'file-finder'
|
||||
|
||||
describe 'FileFinder', ->
|
||||
finder = null
|
||||
urls = null
|
||||
|
||||
beforeEach ->
|
||||
urls = ['app.coffee', 'buffer.coffee', 'atom/app.coffee', 'atom/buffer.coffee']
|
||||
finder = FileFinder.build {urls}
|
||||
|
||||
describe "initialize", ->
|
||||
it "populates the ol with all urls", ->
|
||||
expect(finder.urlList.children('li').length).toBe urls.length
|
||||
|
||||
describe "when characters are typed into the input element", ->
|
||||
it "displays matching urls in the ol element", ->
|
||||
expect(finder.urlList.find('li')).not.toExist()
|
||||
|
||||
finder.input.val('ap')
|
||||
finder.input.keyup()
|
||||
|
||||
@@ -26,6 +29,9 @@ describe 'FileFinder', ->
|
||||
expect(finder.urlList.find('li:contains(atom/app.coffee)').length).toBe 1
|
||||
|
||||
describe "findMatches(queryString)", ->
|
||||
it "returns all urls if queryString is empty", ->
|
||||
expect(finder.findMatches('')).toEqual urls
|
||||
|
||||
it "returns urls sorted by score of match against the given query", ->
|
||||
expect(finder.findMatches('ap')).toEqual ["app.coffee", "atom/app.coffee"]
|
||||
expect(finder.findMatches('a/ap')).toEqual ["atom/app.coffee"]
|
||||
|
||||
@@ -11,17 +11,27 @@ describe "RootView", ->
|
||||
rootView.addPane $('<div id="foo">')
|
||||
expect(rootView.vertical.children().length).toBe 2
|
||||
|
||||
xdescribe "toggleFileFinder", ->
|
||||
it "shows the FileFinder when it is not on screen and hides it when it is", ->
|
||||
#expect(rootView.find('.file-finder')).not.toExist()
|
||||
# rootView.toggleFileFinder()
|
||||
# expect(rootView.find('.file-finder')).toExist()
|
||||
# rootView.toggleFileFinder()
|
||||
# expect(rootView.find('.file-finder')).not.toExist()
|
||||
describe "toggleFileFinder", ->
|
||||
describe "when the editor has a url", ->
|
||||
beforeEach ->
|
||||
rootView.editor.open require.resolve('window.coffee')
|
||||
|
||||
it "shows urls for all files in the same directory as editor.url", ->
|
||||
rootView.editor.open require.resolve('window.coffee')
|
||||
rootView.toggleFileFinder()
|
||||
expect(rootView.fileFinder.urlList.length).toBeGreaterThan 1
|
||||
it "shows the FileFinder when it is not on screen and hides it when it is", ->
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
rootView.toggleFileFinder()
|
||||
expect(rootView.find('.file-finder')).toExist()
|
||||
rootView.toggleFileFinder()
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
|
||||
it "shows urls for all files in the same directory as editor.url", ->
|
||||
rootView.toggleFileFinder()
|
||||
expect(rootView.fileFinder.urlList.children('li').length).toBeGreaterThan 1
|
||||
|
||||
describe "when the editor has no url", ->
|
||||
it "does not open the FileFinder", ->
|
||||
expect(rootView.editor.buffer.url).toBeUndefined()
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
rootView.toggleFileFinder()
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ class Editor extends Template
|
||||
buffer: null
|
||||
editorElement: null
|
||||
|
||||
initialize: ({url}) ->
|
||||
initialize: () ->
|
||||
@buildAceEditor()
|
||||
@open(url)
|
||||
@open()
|
||||
|
||||
shutdown: ->
|
||||
@destroy()
|
||||
@@ -25,7 +25,6 @@ class Editor extends Template
|
||||
@aceEditor.destroy()
|
||||
|
||||
open: (url) ->
|
||||
$atomController.url = url
|
||||
@buffer = new Buffer(url)
|
||||
session = new EditSession(@buffer.aceDocument, @buffer.getMode())
|
||||
@aceEditor.setSession(session)
|
||||
|
||||
@@ -14,6 +14,7 @@ class FileFinder extends Template
|
||||
urls: null
|
||||
|
||||
initialize: ({@urls}) ->
|
||||
@populateUrlList()
|
||||
|
||||
populateUrlList: ->
|
||||
@urlList.empty()
|
||||
@@ -21,6 +22,7 @@ class FileFinder extends Template
|
||||
@urlList.append $("<li>#{url}</li>")
|
||||
|
||||
findMatches: (query) ->
|
||||
return @urls unless query
|
||||
scoredUrls = ({url, score: stringScore(url, query)} for url in @urls)
|
||||
sortedUrls = scoredUrls.sort (a, b) -> a.score > b.score
|
||||
urlAndScore.url for urlAndScore in sortedUrls when urlAndScore.score > 0
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
$ = require 'jquery'
|
||||
fs = require 'fs'
|
||||
|
||||
Editor = require 'editor'
|
||||
FileFinder = require 'file-finder'
|
||||
@@ -16,7 +17,7 @@ class RootView extends Template
|
||||
@div id: 'app-horizontal', =>
|
||||
@div id: 'app-vertical', outlet: 'vertical', =>
|
||||
@div id: 'main', outlet: 'main', =>
|
||||
@subview 'editor', Editor.build(url: $atomController.url?.toString())
|
||||
@subview 'editor', Editor.build()
|
||||
|
||||
viewProperties:
|
||||
addPane: (view) ->
|
||||
@@ -25,10 +26,14 @@ class RootView extends Template
|
||||
@main.after(pane)
|
||||
|
||||
toggleFileFinder: ->
|
||||
return unless @editor.buffer.url
|
||||
|
||||
if @fileFinder
|
||||
@fileFinder.remove()
|
||||
@fileFinder = null
|
||||
else
|
||||
@fileFinder = FileFinder.build(urls: [@editor.buffer.url])
|
||||
directory = fs.directory @editor.buffer.url
|
||||
urls = fs.list directory
|
||||
@fileFinder = FileFinder.build({urls})
|
||||
@addPane(@fileFinder)
|
||||
@fileFinder.input.focus()
|
||||
|
||||
@@ -16,6 +16,7 @@ windowAdditions =
|
||||
@keyBindings = {}
|
||||
@menuItemActions = {}
|
||||
@rootView = RootView.attach()
|
||||
@rootView.editor.open $atomController.url?.toString()
|
||||
@registerEventHandlers()
|
||||
@bindKeys()
|
||||
@bindMenuItems()
|
||||
|
||||
Reference in New Issue
Block a user