Add Editor.setBuffer

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-05 11:13:55 -08:00
parent 4121b2076e
commit aee7df0b9f
4 changed files with 24 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
Buffer = require 'buffer'
Editor = require 'editor'
$ = require 'jquery'
ck = require 'coffeekup'
@@ -29,6 +30,20 @@ describe "Editor", ->
editor.destroy()
expect(editor.aceEditor.destroy).toHaveBeenCalled()
describe "setBuffer(buffer)", ->
it "sets the document on the aceSession", ->
buffer = new Buffer filePath
editor.setBuffer buffer
fileContents = fs.read(filePath)
expect(editor.getAceSession().getValue()).toBe fileContents
it "sets the language mode based on the file extension", ->
buffer = new Buffer "something.js"
editor.setBuffer buffer
expect(editor.getAceSession().getMode().name).toBe 'javascript'
describe "open(url)", ->
describe "when called with a url", ->
it "loads a buffer for the given url into the editor", ->

View File

@@ -51,7 +51,7 @@ describe "RootView", ->
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).not.toExist()
fit "shows all relative file paths for the current project", ->
it "shows all relative file paths for the current project", ->
waitsForPromise ->
rootView.toggleFileFinder()
@@ -73,7 +73,7 @@ describe "RootView", ->
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).not.toExist()
fdescribe "when a path is selected in the file finder", ->
describe "when a path is selected in the file finder", ->
it "opens the file associated with that path in the editor", ->
waitsForPromise -> rootView.toggleFileFinder()
runs ->

View File

@@ -12,7 +12,6 @@ class Editor extends Template
viewProperties:
aceEditor: null
buffer: null
editorElement: null
initialize: () ->
@buildAceEditor()
@@ -24,11 +23,13 @@ class Editor extends Template
destroy: ->
@aceEditor.destroy()
open: (url) ->
@buffer = new Buffer(url)
setBuffer: (@buffer) ->
session = new EditSession(@buffer.aceDocument, @buffer.getMode())
@aceEditor.setSession(session)
open: (url) ->
@setBuffer(new Buffer(url))
buildAceEditor: ->
@aceEditor = ace.edit this[0]
@aceEditor.setTheme(require "ace/theme/twilight")

View File

@@ -39,6 +39,8 @@ class RootView extends Template
else
@project.getFilePaths().done (paths) =>
relativePaths = (path.replace(@project.url, "") for path in paths)
@fileFinder = FileFinder.build({urls: relativePaths, selected: (relativePath) => @editor.open(@project.url + relativePath)})
@fileFinder = FileFinder.build
urls: relativePaths
selected: (relativePath) => @editor.open(@project.url + relativePath)
@addPane(@fileFinder)
@fileFinder.input.focus()