mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Remove initialText option from TextBuffer constructor
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user