diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index e11123a42..2b6ec7486 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -79,10 +79,21 @@ describe "Editor", -> expect(editor.lines.find('.line:eq(8)').text()).toBe ': right.push(current);' expect(editor.lines.find('.line:eq(9)').text()).toBe ' }' - it "unwraps lines when softwrap is disabled", -> + it "changes the max line length when the window size changes", -> + editor.width(editor.charWidth * 40) + $(window).trigger 'resize' + expect(editor.lines.find('.line').length).toBe 19 + expect(editor.lines.find('pre:eq(4)').text()).toBe "left = [], right = [];" + expect(editor.lines.find('pre:eq(5)').text()).toBe " while(items.length > 0) {" + + 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 = [];' + spyOn(editor, 'setMaxLineLength') + $(window).trigger 'resize' + expect(editor.setMaxLineLength).not.toHaveBeenCalled() + describe "cursor movement", -> describe ".setCursorPosition({row, column})", -> beforeEach -> diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index eec85157c..26aaa3c41 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -178,7 +178,7 @@ class Editor extends View toggleSoftWrap: -> @setSoftWrap(not @softWrap) - setSoftWrap: (@softWrap) -> + setMaxLineLength: -> maxLength = if @softWrap Math.floor(@width() / @charWidth) @@ -187,6 +187,14 @@ class Editor extends View @lineWrapper.setMaxLength(maxLength) + setSoftWrap: (@softWrap) -> + @setMaxLineLength() + if @softWrap + @_setMaxLineLength = => @setMaxLineLength() + $(window).on 'resize', @_setMaxLineLength + else + $(window).off 'resize', @_setMaxLineLength + clipPosition: ({row, column}) -> if row > @buffer.lastRow() row = @buffer.lastRow()