Move soft wrap state from EditSession to DisplayBuffer

This commit is contained in:
Kevin Sawicki
2013-08-22 16:57:14 -07:00
parent a39e136c43
commit c33f7cde2a
2 changed files with 13 additions and 16 deletions

View File

@@ -14,14 +14,9 @@ DefaultSoftWrapColumn = 1000000
module.exports =
class DisplayBuffer
screenLines: null
rowMap: null
tokenizedBuffer: null
markers: null
foldsByMarkerId: null
@acceptsDocuments: true
registerDeserializer(this)
@version: 1
@deserialize: (state) -> new this(state)
@@ -32,13 +27,15 @@ class DisplayBuffer
@tokenizedBuffer = deserialize(@state.get('tokenizedBuffer'))
@buffer = @tokenizedBuffer.buffer
else
{@buffer, softWrapColumn} = optionsOrState
{@buffer, softWrap, softWrapColumn} = optionsOrState
@id = guid.create().toString()
@tokenizedBuffer = new TokenizedBuffer(optionsOrState)
@state = site.createDocument
deserializer: @constructor.name
version: @constructor.version
id: @id
tokenizedBuffer: @tokenizedBuffer.getState()
softWrap: softWrap ? false
softWrapColumn: softWrapColumn ? DefaultSoftWrapColumn
@markers = {}
@@ -79,6 +76,10 @@ class DisplayBuffer
# visible - A {Boolean} indicating of the tokenized buffer is shown
setVisible: (visible) -> @tokenizedBuffer.setVisible(visible)
setSoftWrap: (softWrap) -> @state.set('softWrap', softWrap)
getSoftWrap: -> @state.get('softWrap')
# Defines the limit at which the buffer begins to soft wrap text.
#
# softWrapColumn - A {Number} defining the soft wrap limit.

View File

@@ -22,7 +22,7 @@ class EditSession
### Internal ###
@version: 4
@version: 5
@deserialize: (state) ->
new EditSession(state)
@@ -56,13 +56,12 @@ class EditSession
else
{buffer, displayBuffer, tabLength, softTabs, softWrap, suppressCursorCreation} = optionsOrState
@id = guid.create().toString()
displayBuffer ?= new DisplayBuffer({buffer, tabLength})
displayBuffer ?= new DisplayBuffer({buffer, tabLength, softWrap})
@state = site.createDocument
deserializer: @constructor.name
version: @constructor.version
id: @id
displayBuffer: displayBuffer.getState()
softWrap: softWrap ? false
softTabs: buffer.usesSoftTabs() ? softTabs ? true
scrollTop: 0
scrollLeft: 0
@@ -122,8 +121,7 @@ class EditSession
tabLength = @getTabLength()
displayBuffer = @displayBuffer.copy()
softTabs = @getSoftTabs()
softWrap = @getSoftWrap()
newEditSession = new EditSession({@buffer, displayBuffer, tabLength, softTabs, softWrap, suppressCursorCreation: true})
newEditSession = new EditSession({@buffer, displayBuffer, tabLength, softTabs, suppressCursorCreation: true})
newEditSession.setScrollTop(@getScrollTop())
newEditSession.setScrollLeft(@getScrollLeft())
for marker in @findMarkers(editSessionId: @id)
@@ -212,14 +210,12 @@ class EditSession
# Retrieves whether soft tabs are enabled.
#
# Returns a {Boolean}.
getSoftWrap: ->
@state.get('softWrap')
getSoftWrap: -> @displayBuffer.getSoftWrap()
# Defines whether to use soft wrapping of text.
#
# softTabs - A {Boolean} which, if `true`, indicates that you want soft wraps.
setSoftWrap: (softWrap) ->
@state.set('softWrap', softWrap)
setSoftWrap: (softWrap) -> @displayBuffer.setSoftWrap(softWrap)
# Retrieves that character used to indicate a tab.
#