From da1e5f5c1052c710de6a2c8a21b0e7ed5bc7849f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 22 Aug 2013 17:09:49 -0700 Subject: [PATCH] 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. --- spec/editor-spec.coffee | 8 ++++++++ src/display-buffer.coffee | 5 ++--- src/edit-session.coffee | 2 ++ src/editor.coffee | 9 ++++----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 13a5a2808..e9b305bd1 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -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 diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index 891810ae4..733693954 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -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]) diff --git a/src/edit-session.coffee b/src/edit-session.coffee index e61ec12c3..cc3e2ceca 100644 --- a/src/edit-session.coffee +++ b/src/edit-session.coffee @@ -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') diff --git a/src/editor.coffee b/src/editor.coffee index de4dfa02b..0fdc341c4 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -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. #