Max line length is preserved when a new buffer is assigned to an editor.

This commit is contained in:
Nathan Sobo
2012-04-03 15:33:27 -06:00
parent fb915f9c1c
commit 68bd79f8c2
3 changed files with 16 additions and 10 deletions

View File

@@ -196,7 +196,7 @@ class Editor extends View
@trigger 'buffer-path-change'
@buffer.on "path-change.editor#{@id}", => @trigger 'buffer-path-change'
@renderer = new Renderer(@buffer)
@renderer = new Renderer(@buffer, { maxLineLength: @calcMaxLineLength() })
@renderLines()
@gutter.renderLineNumbers()
@@ -277,13 +277,14 @@ class Editor extends View
toggleSoftWrap: ->
@setSoftWrap(not @softWrap)
setMaxLineLength: (maxLineLength) ->
maxLineLength ?=
if @softWrap
Math.floor(@scroller.width() / @charWidth)
else
Infinity
calcMaxLineLength: ->
if @softWrap
Math.floor(@scroller.width() / @charWidth)
else
Infinity
setMaxLineLength: (maxLineLength) ->
maxLineLength ?= @calcMaxLineLength()
@renderer.setMaxLineLength(maxLineLength) if maxLineLength
createFold: (range) ->
@@ -406,7 +407,6 @@ class Editor extends View
foldSelection: -> @getSelection().fold()
undo: ->
@buffer.undo()

View File

@@ -18,10 +18,10 @@ class Renderer
lastHighlighterChangeEvent: null
foldPlaceholderLength: 3
constructor: (@buffer) ->
constructor: (@buffer, options={}) ->
@id = @constructor.idCounter++
@highlighter = new Highlighter(@buffer)
@maxLineLength = Infinity
@maxLineLength = options.maxLineLength ? Infinity
@activeFolds = {}
@foldsById = {}
@buildLineMap()