diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 094077dea..f47649201 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -13,7 +13,6 @@ describe "Editor", -> beforeEach -> filePath = require.resolve 'fixtures/sample.txt' tempFilePath = '/tmp/temp.txt' - spyOn(Editor.prototype.viewProperties, 'open').andCallThrough() editor = Editor.build() afterEach -> @@ -44,41 +43,19 @@ describe "Editor", -> 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", -> - editor.open(filePath) - fileContents = fs.read(filePath) - expect(editor.getAceSession().getValue()).toBe fileContents - expect(editor.buffer.url).toBe(filePath) - expect(editor.buffer.getText()).toEqual fileContents - - it "sets the mode on the session based on the file extension", -> - editor.open('something.js') - expect(editor.getAceSession().getMode().name).toBe 'javascript' - - editor.open('something.text') - expect(editor.getAceSession().getMode().name).toBe 'text' - - describe "when called with null", -> - it "loads an empty buffer with no url", -> - editor.open() - expect(editor.getAceSession().getValue()).toBe "" - expect(editor.buffer.url).toBeUndefined() - expect(editor.buffer.getText()).toEqual "" - describe "when the text is changed via the ace editor", -> it "updates the buffer text", -> - editor.open(filePath) - expect(editor.buffer.getText()).not.toMatch /^.ooo/ + buffer = new Buffer(filePath) + editor.setBuffer(buffer) + expect(buffer.getText()).not.toMatch /^.ooo/ editor.getAceSession().insert {row: 0, column: 1}, 'ooo' - expect(editor.buffer.getText()).toMatch /^.ooo/ + expect(buffer.getText()).toMatch /^.ooo/ describe "save", -> describe "when the current buffer has a url", -> beforeEach -> - editor.open tempFilePath - expect(editor.buffer.url).toBe tempFilePath + buffer = new Buffer(tempFilePath) + editor.setBuffer(buffer) it "saves the current buffer to disk", -> editor.buffer.setText 'Edited buffer!' diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 9cf6f3fe7..13e387560 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -15,7 +15,7 @@ class Editor extends Template initialize: () -> @buildAceEditor() - @open() + @setBuffer(new Buffer) shutdown: -> @destroy() @@ -27,9 +27,6 @@ class Editor extends Template 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") diff --git a/src/atom/root-view.coffee b/src/atom/root-view.coffee index 6e51e798f..4c1af06de 100644 --- a/src/atom/root-view.coffee +++ b/src/atom/root-view.coffee @@ -2,6 +2,7 @@ $ = require 'jquery' fs = require 'fs' Template = require 'template' +Buffer = require 'buffer' Editor = require 'editor' FileFinder = require 'file-finder' Project = require 'project' @@ -23,7 +24,7 @@ class RootView extends Template if url @project = new Project(fs.directory(url)) - @editor.open(url) if fs.isFile(url) + @editor.setBuffer(new Buffer(url)) if fs.isFile(url) addPane: (view) -> pane = $('