SoftWrap state is stored in EditSessions, but it is set and toggled via Editor.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-06-20 09:28:11 -07:00
parent d1c1f3cfce
commit af9aec7cbc
4 changed files with 19 additions and 16 deletions

View File

@@ -10,7 +10,7 @@ describe "EditSession", ->
buffer: buffer
tabText: ' '
autoIndent: false
softWrapColumn: Infinity
softWrap: false
lineLengths = buffer.getLines().map (line) -> line.length

View File

@@ -24,11 +24,12 @@ class EditSession
selections: null
autoIndent: true
softTabs: true
softWrap: false
constructor: ({@buffer, @tabText, @autoIndent, @softTabs, @softWrapColumn}) ->
constructor: ({@buffer, @tabText, @autoIndent, @softTabs, @softWrap}) ->
@id = @constructor.idCounter++
@softTabs ?= true
@displayBuffer = new DisplayBuffer(@buffer, { @softWrapColumn, @tabText })
@displayBuffer = new DisplayBuffer(@buffer, { @tabText })
@tokenizedBuffer = @displayBuffer.tokenizedBuffer
@cursors = []
@selections = []
@@ -70,6 +71,9 @@ class EditSession
setAutoIndent: (@autoIndent) ->
setSoftTabs: (@softTabs) ->
getSoftWrap: -> @softWrap
setSoftWrap: (@softWrap) ->
clipBufferPosition: (bufferPosition, options) ->
{ row, column } = Point.fromObject(bufferPosition)
row = 0 if row < 0

View File

@@ -33,7 +33,6 @@ class Editor extends View
vScrollMargin: 2
hScrollMargin: 10
softWrap: false
lineHeight: null
charWidth: null
charHeight: null
@@ -74,7 +73,7 @@ class Editor extends View
else if @mini
editSession = new EditSession
buffer: new Buffer()
softWrapColumn: null
softWrap: false
tabText: " "
autoIndent: false
softTabs: true
@@ -337,7 +336,7 @@ class Editor extends View
@subscribeToFontSize()
@calculateDimensions()
@hiddenInput.width(@charWidth)
@setSoftWrapColumn() if @softWrap
@setSoftWrapColumn() if @activeEditSession.getSoftWrap()
$(window).on "resize.editor#{@id}", => @updateRenderedLines()
@focus() if @isFocused
@@ -436,7 +435,7 @@ class Editor extends View
@scrollTop(desiredTop)
scrollHorizontally: (pixelPosition) ->
return if @softWrap
return if @activeEditSession.getSoftWrap()
charsInView = @scrollView.width() / @charWidth
maxScrollMargin = Math.floor((charsInView - 1) / 2)
@@ -471,17 +470,18 @@ class Editor extends View
@activeEditSession.setScrollLeft(@scrollView.scrollLeft())
toggleSoftWrap: ->
@setSoftWrap(not @softWrap)
@setSoftWrap(not @activeEditSession.getSoftWrap())
calcSoftWrapColumn: ->
if @softWrap
if @activeEditSession.getSoftWrap()
Math.floor(@scrollView.width() / @charWidth)
else
Infinity
setSoftWrap: (@softWrap, softWrapColumn=undefined) ->
setSoftWrap: (softWrap, softWrapColumn=undefined) ->
@activeEditSession.setSoftWrap(softWrap)
@setSoftWrapColumn(softWrapColumn) if @attached
if @softWrap
if @activeEditSession.getSoftWrap()
@addClass 'soft-wrap'
@_setSoftWrapColumn = => @setSoftWrapColumn()
$(window).on 'resize', @_setSoftWrapColumn

View File

@@ -14,12 +14,11 @@ class Project
tabText: null
autoIndent: null
softTabs: null
softWrapColumn: null
softWrap: null
constructor: (path) ->
@setPath(path)
@editSessions = []
@setTabText(' ')
@setAutoIndent(true)
@setSoftTabs(true)
@@ -73,8 +72,8 @@ class Project
getSoftTabs: -> @softTabs
setSoftTabs: (@softTabs) ->
getSoftWrapColumn: -> @softWrapColumn
setSoftWrapColumn: (@softWrapColumn) ->
getSoftWrap: -> @softWrap
setSoftWrap: (@softWrap) ->
open: (filePath) ->
if filePath?
@@ -88,7 +87,7 @@ class Project
tabText: @getTabText()
autoIndent: @getAutoIndent()
softTabs: @getSoftTabs()
softWrapColumn: @getSoftWrapColumn()
softWrap: @getSoftWrap()
@editSessions.push editSession
editSession