mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Re-wrap lines when window size changes.
This commit is contained in:
@@ -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 ->
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user