mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-12-27 08:32:30 +03:00
Merge pull request #1078 from atom/ks-soft-wrap-resize
Update soft wrap column on editor resize
This commit is contained in:
commit
1ef5809b24
@ -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)
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user