Serialize all TextEditor parameters needed for the DisplayLayer

This commit is contained in:
Max Brunsfeld
2016-08-15 15:51:22 -07:00
parent 4bcdbf4d2f
commit 0d099d2fd5
2 changed files with 42 additions and 15 deletions

View File

@@ -38,6 +38,29 @@ describe "TextEditor", ->
expect(editor2.isFoldedAtBufferRow(4)).toBeTruthy()
editor2.destroy()
it "restores the editor's layout configuration", ->
editor.update({
softTabs: true
atomicSoftTabs: true
tabLength: 12
softWrapped: true
softWrapAtPreferredLineLength: true
softWrapHangingIndentLength: 8
invisibles: {space: 'S'}
showInvisibles: true
editorWidthInChars: 120
})
editor2 = TextEditor.deserialize(editor.serialize(), atom)
expect(editor2.getSoftTabs()).toBe(editor.getSoftTabs())
expect(editor2.hasAtomicSoftTabs()).toBe(editor.hasAtomicSoftTabs())
expect(editor2.getTabLength()).toBe(editor.getTabLength())
expect(editor2.getSoftWrapColumn()).toBe(editor.getSoftWrapColumn())
expect(editor2.getSoftWrapHangingIndentLength()).toBe(editor.getSoftWrapHangingIndentLength())
expect(editor2.getInvisibles()).toEqual(editor.getInvisibles())
expect(editor2.getEditorWidthInChars()).toBe(editor.getEditorWidthInChars())
describe "when the editor is constructed with the largeFileMode option set to true", ->
it "loads the editor but doesn't tokenize", ->
editor = null

View File

@@ -338,21 +338,25 @@ class TextEditor extends Model
serialize: ->
tokenizedBufferState = @tokenizedBuffer.serialize()
deserializer: 'TextEditor'
version: @serializationVersion
id: @id
softTabs: @softTabs
firstVisibleScreenRow: @getFirstVisibleScreenRow()
firstVisibleScreenColumn: @getFirstVisibleScreenColumn()
selectionsMarkerLayerId: @selectionsMarkerLayer.id
softWrapped: @isSoftWrapped()
editorWidthInChars: @editorWidthInChars
# TODO: Remove this forward-compatible fallback once 1.8 reaches stable.
displayBuffer: {tokenizedBuffer: tokenizedBufferState}
tokenizedBuffer: tokenizedBufferState
largeFileMode: @largeFileMode
displayLayerId: @displayLayer.id
registered: @registered
{
deserializer: 'TextEditor'
version: @serializationVersion
# TODO: Remove this forward-compatible fallback once 1.8 reaches stable.
displayBuffer: {tokenizedBuffer: tokenizedBufferState}
tokenizedBuffer: tokenizedBufferState
displayLayerId: @displayLayer.id
selectionsMarkerLayerId: @selectionsMarkerLayer.id
firstVisibleScreenRow: @getFirstVisibleScreenRow()
firstVisibleScreenColumn: @getFirstVisibleScreenColumn()
@id, @softTabs, @atomicSoftTabs, @tabLength, @softWrapped,
@softWrapHangingIndentLength, @softWrapAtPreferredLineLength,
@preferredLineLength, @mini, @editorWidthInChars, @width, @largeFileMode,
@registered, @invisibles, @showInvisibles, @showIndentGuide
}
subscribeToBuffer: ->
@buffer.retain()