From af9aec7cbc38b8dcac0a035dda9999da057b1aab Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Wed, 20 Jun 2012 09:28:11 -0700 Subject: [PATCH] SoftWrap state is stored in EditSessions, but it is set and toggled via Editor. --- spec/app/edit-session-spec.coffee | 2 +- src/app/edit-session.coffee | 8 ++++++-- src/app/editor.coffee | 16 ++++++++-------- src/app/project.coffee | 9 ++++----- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index aa8df99c9..5031eb9ba 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -10,7 +10,7 @@ describe "EditSession", -> buffer: buffer tabText: ' ' autoIndent: false - softWrapColumn: Infinity + softWrap: false lineLengths = buffer.getLines().map (line) -> line.length diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 242c70251..c38227b80 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -24,11 +24,12 @@ class EditSession selections: null autoIndent: true softTabs: true + softWrap: false - constructor: ({@buffer, @tabText, @autoIndent, @softTabs, @softWrapColumn}) -> + constructor: ({@buffer, @tabText, @autoIndent, @softTabs, @softWrap}) -> @id = @constructor.idCounter++ @softTabs ?= true - @displayBuffer = new DisplayBuffer(@buffer, { @softWrapColumn, @tabText }) + @displayBuffer = new DisplayBuffer(@buffer, { @tabText }) @tokenizedBuffer = @displayBuffer.tokenizedBuffer @cursors = [] @selections = [] @@ -70,6 +71,9 @@ class EditSession setAutoIndent: (@autoIndent) -> setSoftTabs: (@softTabs) -> + getSoftWrap: -> @softWrap + setSoftWrap: (@softWrap) -> + clipBufferPosition: (bufferPosition, options) -> { row, column } = Point.fromObject(bufferPosition) row = 0 if row < 0 diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 2f1a96c8a..9c16bd265 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -33,7 +33,6 @@ class Editor extends View vScrollMargin: 2 hScrollMargin: 10 - softWrap: false lineHeight: null charWidth: null charHeight: null @@ -74,7 +73,7 @@ class Editor extends View else if @mini editSession = new EditSession buffer: new Buffer() - softWrapColumn: null + softWrap: false tabText: " " autoIndent: false softTabs: true @@ -337,7 +336,7 @@ class Editor extends View @subscribeToFontSize() @calculateDimensions() @hiddenInput.width(@charWidth) - @setSoftWrapColumn() if @softWrap + @setSoftWrapColumn() if @activeEditSession.getSoftWrap() $(window).on "resize.editor#{@id}", => @updateRenderedLines() @focus() if @isFocused @@ -436,7 +435,7 @@ class Editor extends View @scrollTop(desiredTop) scrollHorizontally: (pixelPosition) -> - return if @softWrap + return if @activeEditSession.getSoftWrap() charsInView = @scrollView.width() / @charWidth maxScrollMargin = Math.floor((charsInView - 1) / 2) @@ -471,17 +470,18 @@ class Editor extends View @activeEditSession.setScrollLeft(@scrollView.scrollLeft()) toggleSoftWrap: -> - @setSoftWrap(not @softWrap) + @setSoftWrap(not @activeEditSession.getSoftWrap()) calcSoftWrapColumn: -> - if @softWrap + if @activeEditSession.getSoftWrap() Math.floor(@scrollView.width() / @charWidth) else Infinity - setSoftWrap: (@softWrap, softWrapColumn=undefined) -> + setSoftWrap: (softWrap, softWrapColumn=undefined) -> + @activeEditSession.setSoftWrap(softWrap) @setSoftWrapColumn(softWrapColumn) if @attached - if @softWrap + if @activeEditSession.getSoftWrap() @addClass 'soft-wrap' @_setSoftWrapColumn = => @setSoftWrapColumn() $(window).on 'resize', @_setSoftWrapColumn diff --git a/src/app/project.coffee b/src/app/project.coffee index c1139af90..1e66e163c 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -14,12 +14,11 @@ class Project tabText: null autoIndent: null softTabs: null - softWrapColumn: null + softWrap: null constructor: (path) -> @setPath(path) @editSessions = [] - @setTabText(' ') @setAutoIndent(true) @setSoftTabs(true) @@ -73,8 +72,8 @@ class Project getSoftTabs: -> @softTabs setSoftTabs: (@softTabs) -> - getSoftWrapColumn: -> @softWrapColumn - setSoftWrapColumn: (@softWrapColumn) -> + getSoftWrap: -> @softWrap + setSoftWrap: (@softWrap) -> open: (filePath) -> if filePath? @@ -88,7 +87,7 @@ class Project tabText: @getTabText() autoIndent: @getAutoIndent() softTabs: @getSoftTabs() - softWrapColumn: @getSoftWrapColumn() + softWrap: @getSoftWrap() @editSessions.push editSession editSession