diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 87fbce548..36c438ad5 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -106,6 +106,12 @@ describe "Editor", -> expect(editor.lines.find('.line:eq(5)').text()).toBe " while(items.length > 0) {" expect(editor.bufferPositionForScreenPosition(editor.getCursorScreenPosition())).toEqual [3, 60] + it "wraps the lines of any newly assigned buffers", -> + otherBuffer = new Buffer + otherBuffer.setText([1..100].join('')) + editor.setBuffer(otherBuffer) + expect(editor.lines.find('.line').length).toBeGreaterThan(1) + it "unwraps lines and cancels window resize listener when softwrap is disabled", -> editor.toggleSoftWrap() expect(editor.lines.find('.line:eq(3)').text()).toBe ' var pivot = items.shift(), current, left = [], right = [];' diff --git a/src/app/editor.coffee b/src/app/editor.coffee index fa82450f5..8ba0df5d1 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -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() diff --git a/src/app/renderer.coffee b/src/app/renderer.coffee index 14e677062..7cd77770a 100644 --- a/src/app/renderer.coffee +++ b/src/app/renderer.coffee @@ -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()