Merge pull request #1078 from atom/ks-soft-wrap-resize

Update soft wrap column on editor resize
This commit is contained in:
Kevin Sawicki 2013-11-05 09:06:21 -08:00
commit 1ef5809b24
3 changed files with 23 additions and 1 deletions

View File

@ -1656,6 +1656,7 @@ describe "Editor", ->
describe "when soft-wrap is enabled", ->
beforeEach ->
jasmine.unspy(window, 'setTimeout')
editSession.setSoftWrap(true)
editor.attachToDom()
setEditorHeightInLines(editor, 20)
@ -1735,6 +1736,19 @@ describe "Editor", ->
expect(otherEditor.setWidthInChars).toHaveBeenCalled()
otherEditor.remove()
describe "when the editor's width changes", ->
it "updates the width in characters on the edit session", ->
previousSoftWrapColumn = editSession.getSoftWrapColumn()
spyOn(editor, 'setWidthInChars').andCallThrough()
editor.width(editor.width() / 2)
waitsFor ->
editor.setWidthInChars.callCount > 0
runs ->
expect(editSession.getSoftWrapColumn()).toBeLessThan previousSoftWrapColumn
describe "gutter rendering", ->
beforeEach ->
editor.attachToDom(heightInLines: 5.5)

View File

@ -106,8 +106,10 @@ class DisplayBuffer
#
# editorWidthInChars - A {Number} of characters.
setEditorWidthInChars: (editorWidthInChars) ->
previousWidthInChars = @state.get('editorWidthInChars')
@state.set('editorWidthInChars', editorWidthInChars)
@updateWrappedScreenLines() if @getSoftWrap()
if editorWidthInChars isnt previousWidthInChars and @getSoftWrap()
@updateWrappedScreenLines()
getSoftWrapColumn: ->
editorWidthInChars = @state.get('editorWidthInChars')

View File

@ -704,6 +704,12 @@ class Editor extends View
else
@gutter.addClass('drop-shadow')
# Listen for overflow events to detect when the editor's width changes
# to update the soft wrap column.
updateWidthInChars = _.debounce((=> @setWidthInChars()), 100)
@scrollView.on 'overflowchanged', =>
updateWidthInChars() if @[0].classList.contains('soft-wrap')
handleInputEvents: ->
@on 'cursor:moved', =>
return unless @isFocused