mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add Editor.setBuffer
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user