Remove initialText option from TextBuffer constructor

This commit is contained in:
probablycorey
2013-10-25 10:21:11 -07:00
parent 6460cbe288
commit 32bc8a6258
3 changed files with 15 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
TokenizedBuffer = require '../src/tokenized-buffer'
{_} = require 'atom'
describe "TokenizedBuffer", ->
fdescribe "TokenizedBuffer", ->
[tokenizedBuffer, buffer, changeHandler] = []
beforeEach ->
@@ -350,7 +350,8 @@ describe "TokenizedBuffer", ->
describe "when the buffer contains surrogate pairs", ->
beforeEach ->
atom.activatePackage('language-javascript', sync: true)
buffer = project.buildBufferSync 'sample-with-pairs.js', """
buffer = project.buildBufferSync 'sample-with-pairs.js'
buffer.setText """
'abc\uD835\uDF97def'
//\uD835\uDF97xyz
"""
@@ -389,7 +390,8 @@ describe "TokenizedBuffer", ->
atom.activatePackage('language-ruby-on-rails', sync: true)
atom.activatePackage('language-ruby', sync: true)
buffer = project.bufferForPathSync(null, "<div class='name'><%= User.find(2).full_name %></div>")
buffer = project.bufferForPathSync()
buffer.setText "<div class='name'><%= User.find(2).full_name %></div>"
tokenizedBuffer = new TokenizedBuffer({buffer})
tokenizedBuffer.setGrammar(syntax.selectGrammar('test.erb'))
fullyTokenize(tokenizedBuffer)

View File

@@ -219,13 +219,13 @@ class Project
new Array(@buffers...)
# Private: Only to be used in specs
bufferForPathSync: (filePath, text) ->
bufferForPathSync: (filePath) ->
absoluteFilePath = @resolve(filePath)
if filePath
existingBuffer = _.find @buffers, (buffer) -> buffer.getPath() == absoluteFilePath
existingBuffer ? @buildBufferSync(absoluteFilePath, text)
existingBuffer ? @buildBufferSync(absoluteFilePath)
# Private: Given a file path, this retrieves or creates a new {TextBuffer}.
#
@@ -233,23 +233,22 @@ class Project
# `text` is used as the contents of the new buffer.
#
# filePath - A {String} representing a path. If `null`, an "Untitled" buffer is created.
# text - The {String} text to use as a buffer, if the file doesn't have any contents
#
# Returns a promise that resolves to the {TextBuffer}.
bufferForPath: (filePath, text) ->
bufferForPath: (filePath) ->
absoluteFilePath = @resolve(filePath)
if absoluteFilePath
existingBuffer = _.find @buffers, (buffer) -> buffer.getPath() == absoluteFilePath
Q(existingBuffer ? @buildBuffer(absoluteFilePath, text))
Q(existingBuffer ? @buildBuffer(absoluteFilePath))
# Private:
bufferForId: (id) ->
_.find @buffers, (buffer) -> buffer.id is id
# Private: DEPRECATED
buildBufferSync: (absoluteFilePath, initialText) ->
buffer = new TextBuffer({project: this, filePath: absoluteFilePath, initialText})
buildBufferSync: (absoluteFilePath) ->
buffer = new TextBuffer({project: this, filePath: absoluteFilePath})
buffer.loadSync()
@addBuffer(buffer)
buffer
@@ -260,8 +259,8 @@ class Project
# text - The {String} text to use as a buffer
#
# Returns a promise that resolves to the {TextBuffer}.
buildBuffer: (absoluteFilePath, initialText) ->
buffer = new TextBuffer({project: this, filePath: absoluteFilePath, initialText})
buildBuffer: (absoluteFilePath) ->
buffer = new TextBuffer({project: this, filePath: absoluteFilePath})
buffer.load().then (buffer) =>
@addBuffer(buffer)
buffer

View File

@@ -49,7 +49,7 @@ class TextBuffer
@text = @state.get('text')
@loadFromDisk = @state.get('isModified') == false
else
{@project, filePath, initialText} = optionsOrState
{@project, filePath} = optionsOrState
@text = site.createDocument(initialText ? '', shareStrings: true)
@id = guid.create().toString()
@state = site.createDocument
@@ -57,7 +57,7 @@ class TextBuffer
deserializer: @constructor.name
version: @constructor.version
text: @text
@loadFromDisk = not initialText
@loadFromDisk = true
@loaded = false
@subscribe @text, 'changed', @handleTextChange