mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Don’t use atom.assert global in DisplayBuffer
This commit is contained in:
@@ -7,7 +7,7 @@ describe "DisplayBuffer", ->
|
||||
tabLength = 2
|
||||
|
||||
buffer = atom.project.bufferForPathSync('sample.js')
|
||||
displayBuffer = new DisplayBuffer({buffer, tabLength, config: atom.config})
|
||||
displayBuffer = new DisplayBuffer({buffer, tabLength, config: atom.config, assert: ->})
|
||||
changeHandler = jasmine.createSpy 'changeHandler'
|
||||
displayBuffer.onDidChange changeHandler
|
||||
|
||||
@@ -49,7 +49,7 @@ describe "DisplayBuffer", ->
|
||||
|
||||
it "updates the display buffer prior to invoking change handlers registered on the buffer", ->
|
||||
buffer.onDidChange -> expect(displayBuffer2.tokenizedLineForScreenRow(0).text).toBe "testing"
|
||||
displayBuffer2 = new DisplayBuffer({buffer, tabLength, config: atom.config})
|
||||
displayBuffer2 = new DisplayBuffer({buffer, tabLength, config: atom.config, assert: ->})
|
||||
buffer.setText("testing")
|
||||
|
||||
describe "soft wrapping", ->
|
||||
@@ -232,7 +232,7 @@ describe "DisplayBuffer", ->
|
||||
describe "when a newline is inserted, deleted, and re-inserted at the end of a wrapped line (regression)", ->
|
||||
it "correctly renders the original wrapped line", ->
|
||||
buffer = atom.project.buildBufferSync(null, '')
|
||||
displayBuffer = new DisplayBuffer({buffer, tabLength, editorWidthInChars: 30, config: atom.config})
|
||||
displayBuffer = new DisplayBuffer({buffer, tabLength, editorWidthInChars: 30, config: atom.config, assert: ->})
|
||||
displayBuffer.setSoftWrapped(true)
|
||||
|
||||
buffer.insert([0, 0], "the quick brown fox jumps over the lazy dog.")
|
||||
@@ -294,7 +294,7 @@ describe "DisplayBuffer", ->
|
||||
displayBuffer.destroy()
|
||||
buffer.release()
|
||||
buffer = atom.project.bufferForPathSync('two-hundred.txt')
|
||||
displayBuffer = new DisplayBuffer({buffer, tabLength, config: atom.config})
|
||||
displayBuffer = new DisplayBuffer({buffer, tabLength, config: atom.config, assert: ->})
|
||||
displayBuffer.onDidChange changeHandler
|
||||
|
||||
describe "when folds are created and destroyed", ->
|
||||
@@ -408,7 +408,7 @@ describe "DisplayBuffer", ->
|
||||
|
||||
describe "when there is another display buffer pointing to the same buffer", ->
|
||||
it "does not consider folds to be nested inside of folds from the other display buffer", ->
|
||||
otherDisplayBuffer = new DisplayBuffer({buffer, tabLength, config: atom.config})
|
||||
otherDisplayBuffer = new DisplayBuffer({buffer, tabLength, config: atom.config, assert: ->})
|
||||
otherDisplayBuffer.createFold(1, 5)
|
||||
|
||||
displayBuffer.createFold(2, 4)
|
||||
@@ -1154,7 +1154,7 @@ describe "DisplayBuffer", ->
|
||||
describe 'when there are multiple DisplayBuffers for a buffer', ->
|
||||
describe 'when a marker is created', ->
|
||||
it 'the second display buffer will not emit a marker-created event when the marker has been deleted in the first marker-created event', ->
|
||||
displayBuffer2 = new DisplayBuffer({buffer, tabLength, config: atom.config})
|
||||
displayBuffer2 = new DisplayBuffer({buffer, tabLength, config: atom.config, assert: ->})
|
||||
displayBuffer.onDidCreateMarker markerCreated1 = jasmine.createSpy().andCallFake (marker) -> marker.destroy()
|
||||
displayBuffer2.onDidCreateMarker markerCreated2 = jasmine.createSpy()
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ beforeEach ->
|
||||
grammarRegistry: atom.grammars, notificationManager: atom.notifications,
|
||||
setRepresentedFilename: jasmine.createSpy('setRepresentedFilename'),
|
||||
setDocumentEdited: atom.setDocumentEdited.bind(atom), atomVersion: atom.getVersion(),
|
||||
clipboard: atom.clipboard, viewRegistry: atom.views
|
||||
clipboard: atom.clipboard, viewRegistry: atom.views, assert: atom.assert.bind(atom)
|
||||
})
|
||||
atom.themes.workspace = atom.workspace
|
||||
atom.keymaps.keyBindings = _.clone(keyBindingsToRestore)
|
||||
|
||||
@@ -19,7 +19,8 @@ describe "Workspace", ->
|
||||
grammarRegistry: atom.grammars, notificationManager: atom.notifications,
|
||||
clipboard: atom.clipboard, viewRegistry: atom.views,
|
||||
setRepresentedFilename: jasmine.createSpy('setRepresentedFilename'),
|
||||
setDocumentEdited: setDocumentEdited, atomVersion: atom.getVersion()
|
||||
setDocumentEdited: setDocumentEdited, atomVersion: atom.getVersion(),
|
||||
assert: atom.assert.bind(atom)
|
||||
})
|
||||
waits(1)
|
||||
|
||||
@@ -36,7 +37,7 @@ describe "Workspace", ->
|
||||
grammarRegistry: atom.grammars, notificationManager: atom.notifications,
|
||||
clipboard: atom.clipboard, viewRegistry: atom.views,
|
||||
setRepresentedFilename: jasmine.createSpy('setRepresentedFilename'),
|
||||
setDocumentEdited: setDocumentEdited
|
||||
setDocumentEdited: setDocumentEdited, assert: atom.assert.bind(atom)
|
||||
})
|
||||
atom.workspace.deserialize(workspaceState, atom.deserializers)
|
||||
|
||||
@@ -635,7 +636,8 @@ describe "Workspace", ->
|
||||
grammarRegistry: atom.grammars, notificationManager: atom.notifications,
|
||||
clipboard: atom.clipboard, viewRegistry: atom.views,
|
||||
setRepresentedFilename: jasmine.createSpy('setRepresentedFilename'),
|
||||
setDocumentEdited: setDocumentEdited, atomVersion: atom.getVersion()
|
||||
setDocumentEdited: setDocumentEdited, atomVersion: atom.getVersion(),
|
||||
assert: atom.assert.bind(atom)
|
||||
})
|
||||
workspace2.deserialize(state, atom.deserializers)
|
||||
expect(jsPackage.loadGrammarsSync.callCount).toBe 1
|
||||
@@ -694,7 +696,8 @@ describe "Workspace", ->
|
||||
grammarRegistry: atom.grammars, notificationManager: atom.notifications,
|
||||
clipboard: atom.clipboard, viewRegistry: atom.views,
|
||||
setRepresentedFilename: jasmine.createSpy('setRepresentedFilename'),
|
||||
setDocumentEdited: setDocumentEdited, atomVersion: atom.getVersion()
|
||||
setDocumentEdited: setDocumentEdited, atomVersion: atom.getVersion(),
|
||||
assert: atom.assert.bind(atom)
|
||||
})
|
||||
workspace2.deserialize(atom.workspace.serialize(), atom.deserializers)
|
||||
item = atom.workspace.getActivePaneItem()
|
||||
|
||||
@@ -175,7 +175,8 @@ class Atom extends Model
|
||||
@workspace = new Workspace({
|
||||
@config, @project, packageManager: @packages, grammarRegistry: @grammars,
|
||||
notificationManager: @notifications, setRepresentedFilename: @setRepresentedFilename.bind(this),
|
||||
setDocumentEdited: @setDocumentEdited.bind(this), @clipboard, viewRegistry: @views
|
||||
setDocumentEdited: @setDocumentEdited.bind(this), @clipboard, viewRegistry: @views,
|
||||
assert: @assert.bind(this)
|
||||
})
|
||||
@themes.workspace = @workspace
|
||||
|
||||
|
||||
@@ -30,9 +30,10 @@ class DisplayBuffer extends Model
|
||||
@deserialize: (state, atomEnvironment) ->
|
||||
state.tokenizedBuffer = TokenizedBuffer.deserialize(state.tokenizedBuffer)
|
||||
state.config = atomEnvironment.config
|
||||
state.assert = atomEnvironment.assert
|
||||
new this(state)
|
||||
|
||||
constructor: ({tabLength, @editorWidthInChars, @tokenizedBuffer, buffer, ignoreInvisibles, @largeFileMode, @config}={}) ->
|
||||
constructor: ({tabLength, @editorWidthInChars, @tokenizedBuffer, buffer, ignoreInvisibles, @largeFileMode, @config, @assert}={}) ->
|
||||
super
|
||||
|
||||
@emitter = new Emitter
|
||||
@@ -99,7 +100,9 @@ class DisplayBuffer extends Model
|
||||
largeFileMode: @largeFileMode
|
||||
|
||||
copy: ->
|
||||
newDisplayBuffer = new DisplayBuffer({@buffer, tabLength: @getTabLength(), @largeFileMode, @config})
|
||||
newDisplayBuffer = new DisplayBuffer({
|
||||
@buffer, tabLength: @getTabLength(), @largeFileMode, @config, @assert
|
||||
})
|
||||
|
||||
for marker in @findMarkers(displayBufferId: @id)
|
||||
marker.copy(displayBufferId: newDisplayBuffer.id)
|
||||
@@ -1067,8 +1070,8 @@ class DisplayBuffer extends Model
|
||||
tokenizedLinesCount = @tokenizedBuffer.getLineCount()
|
||||
bufferLinesCount = @buffer.getLineCount()
|
||||
|
||||
atom.assert screenLinesCount is tokenizedLinesCount, "Display buffer line count out of sync with tokenized buffer", (error) ->
|
||||
@assert screenLinesCount is tokenizedLinesCount, "Display buffer line count out of sync with tokenized buffer", (error) ->
|
||||
error.metadata = {screenLinesCount, tokenizedLinesCount, bufferLinesCount}
|
||||
|
||||
atom.assert screenLinesCount is bufferLinesCount, "Display buffer line count out of sync with buffer", (error) ->
|
||||
@assert screenLinesCount is bufferLinesCount, "Display buffer line count out of sync with buffer", (error) ->
|
||||
error.metadata = {screenLinesCount, tokenizedLinesCount, bufferLinesCount}
|
||||
|
||||
@@ -79,6 +79,7 @@ class TextEditor extends Model
|
||||
state.clipboard = atomEnvironment.clipboard
|
||||
state.viewRegistry = atomEnvironment.views
|
||||
state.project = atomEnvironment.project
|
||||
state.assert = atomEnvironment.assert.bind(atomEnvironment)
|
||||
new this(state)
|
||||
|
||||
constructor: (params={}) ->
|
||||
@@ -88,7 +89,7 @@ class TextEditor extends Model
|
||||
@softTabs, @scrollRow, @scrollColumn, initialLine, initialColumn, tabLength,
|
||||
softWrapped, @displayBuffer, buffer, suppressCursorCreation, @mini, @placeholderText,
|
||||
lineNumberGutterVisible, largeFileMode, @config, @notificationManager, @clipboard,
|
||||
@viewRegistry, @project
|
||||
@viewRegistry, @project, @assert
|
||||
} = params
|
||||
|
||||
throw new Error("Must pass a config parameter when constructing TextEditors") unless @config?
|
||||
@@ -96,6 +97,7 @@ class TextEditor extends Model
|
||||
throw new Error("Must pass a clipboard parameter when constructing TextEditors") unless @clipboard?
|
||||
throw new Error("Must pass a viewRegistry parameter when constructing TextEditors") unless @viewRegistry?
|
||||
throw new Error("Must pass a project parameter when constructing TextEditors") unless @project?
|
||||
throw new Error("Must pass an assert parameter when constructing TextEditors") unless @assert?
|
||||
|
||||
@emitter = new Emitter
|
||||
@disposables = new CompositeDisposable
|
||||
@@ -103,7 +105,10 @@ class TextEditor extends Model
|
||||
@selections = []
|
||||
|
||||
buffer ?= new TextBuffer
|
||||
@displayBuffer ?= new DisplayBuffer({buffer, tabLength, softWrapped, ignoreInvisibles: @mini, largeFileMode, @config})
|
||||
@displayBuffer ?= new DisplayBuffer({
|
||||
buffer, tabLength, softWrapped, ignoreInvisibles: @mini, largeFileMode,
|
||||
@config, @assert
|
||||
})
|
||||
@buffer = @displayBuffer.buffer
|
||||
|
||||
for marker in @findMarkers(@getSelectionMarkerAttributes())
|
||||
@@ -470,7 +475,7 @@ class TextEditor extends Model
|
||||
softTabs = @getSoftTabs()
|
||||
newEditor = new TextEditor({
|
||||
@buffer, displayBuffer, @tabLength, softTabs, suppressCursorCreation: true,
|
||||
@config, @notificationManager, @clipboard, @viewRegistry, @project
|
||||
@config, @notificationManager, @clipboard, @viewRegistry, @project, @assert
|
||||
})
|
||||
for marker in @findMarkers(editorId: @id)
|
||||
marker.copy(editorId: newEditor.id, preserveFolds: true)
|
||||
|
||||
@@ -21,7 +21,7 @@ class TokenizedBuffer extends Model
|
||||
configSettings: null
|
||||
changeCount: 0
|
||||
|
||||
@deserialize: (state) ->
|
||||
@deserialize: (state, atomEnvironment) ->
|
||||
state.buffer = atom.project.bufferForPathSync(state.bufferPath)
|
||||
new this(state)
|
||||
|
||||
|
||||
@@ -28,9 +28,11 @@ class Workspace extends Model
|
||||
|
||||
{
|
||||
@packageManager, @config, @project, @grammarRegistry, @notificationManager,
|
||||
@clipboard, @viewRegistry, @setRepresentedFilename, @setDocumentEdited
|
||||
@clipboard, @viewRegistry, @setRepresentedFilename, @setDocumentEdited, @assert
|
||||
} = params
|
||||
|
||||
debugger unless @assert?
|
||||
|
||||
@emitter = new Emitter
|
||||
@openers = []
|
||||
@destroyedItemURIs = []
|
||||
@@ -458,7 +460,7 @@ class Workspace extends Model
|
||||
@buildTextEditor(_.extend({buffer, largeFileMode}, options))
|
||||
|
||||
buildTextEditor: (params) ->
|
||||
new TextEditor(_.extend({@config, @notificationManager, @clipboard, @viewRegistry, @project}, params))
|
||||
new TextEditor(_.extend({@config, @notificationManager, @clipboard, @viewRegistry, @project, @assert}, params))
|
||||
|
||||
# Public: Asynchronously reopens the last-closed item's URI if it hasn't already been
|
||||
# reopened.
|
||||
|
||||
Reference in New Issue
Block a user