mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Always update the soft wrap column when the window resizes
This allows the edit session and display buffer to always be notified of soft wrap column changes regardless of their initial soft wrap state.
This commit is contained in:
@@ -2670,3 +2670,11 @@ describe "Editor", ->
|
||||
|
||||
for rowNumber in [1..5]
|
||||
expect(editor.lineElementForScreenRow(rowNumber).text()).toBe buffer.lineForRow(rowNumber)
|
||||
|
||||
describe "when the window is resized", ->
|
||||
it "updates the active edit session with the current soft wrap column", ->
|
||||
editor.attachToDom()
|
||||
expect(editor.activeEditSession.getSoftWrapColumn()).toBe 78
|
||||
editor.width(editor.width() * 2)
|
||||
$(window).trigger 'resize'
|
||||
expect(editor.activeEditSession.getSoftWrapColumn()).toBe 155
|
||||
|
||||
@@ -10,8 +10,6 @@ Token = require 'token'
|
||||
DisplayBufferMarker = require 'display-buffer-marker'
|
||||
Subscriber = require 'subscriber'
|
||||
|
||||
DefaultSoftWrapColumn = 1000000
|
||||
|
||||
module.exports =
|
||||
class DisplayBuffer
|
||||
@acceptsDocuments: true
|
||||
@@ -36,7 +34,7 @@ class DisplayBuffer
|
||||
id: @id
|
||||
tokenizedBuffer: @tokenizedBuffer.getState()
|
||||
softWrap: softWrap ? false
|
||||
softWrapColumn: softWrapColumn ? DefaultSoftWrapColumn
|
||||
softWrapColumn: softWrapColumn
|
||||
|
||||
@markers = {}
|
||||
@foldsByMarkerId = {}
|
||||
@@ -408,6 +406,7 @@ class DisplayBuffer
|
||||
# Returns a {Number} representing the `line` position where the wrap would take place.
|
||||
# Returns `null` if a wrap wouldn't occur.
|
||||
findWrapColumn: (line, softWrapColumn=@getSoftWrapColumn()) ->
|
||||
return unless @getSoftWrap()
|
||||
return unless line.length > softWrapColumn
|
||||
|
||||
if /\s/.test(line[softWrapColumn])
|
||||
|
||||
@@ -198,6 +198,8 @@ class EditSession
|
||||
# softWrapColumn - A {Number} defining the soft wrap limit
|
||||
setSoftWrapColumn: (@softWrapColumn) -> @displayBuffer.setSoftWrapColumn(@softWrapColumn)
|
||||
|
||||
getSoftWrapColumn: -> @displayBuffer.getSoftWrapColumn()
|
||||
|
||||
getSoftTabs: ->
|
||||
@state.get('softTabs')
|
||||
|
||||
|
||||
@@ -719,8 +719,10 @@ class Editor extends View
|
||||
return if @attached
|
||||
@attached = true
|
||||
@calculateDimensions()
|
||||
@setSoftWrapColumn() if @activeEditSession.getSoftWrap()
|
||||
@subscribe $(window), "resize.editor-#{@id}", => @requestDisplayUpdate()
|
||||
@setSoftWrapColumn()
|
||||
@subscribe $(window), "resize.editor-#{@id}", =>
|
||||
@setSoftWrapColumn()
|
||||
@requestDisplayUpdate()
|
||||
@focus() if @isFocused
|
||||
|
||||
if pane = @getPane()
|
||||
@@ -919,11 +921,8 @@ class Editor extends View
|
||||
if @activeEditSession.getSoftWrap()
|
||||
@addClass 'soft-wrap'
|
||||
@scrollLeft(0)
|
||||
@_setSoftWrapColumn = => @setSoftWrapColumn()
|
||||
$(window).on "resize.editor-#{@id}", @_setSoftWrapColumn
|
||||
else
|
||||
@removeClass 'soft-wrap'
|
||||
$(window).off 'resize', @_setSoftWrapColumn
|
||||
|
||||
# Sets the font size for the editor.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user