From 911a417cb8666ff0ac96a7a0763415dd160aba68 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 5 Jun 2012 12:38:53 -0600 Subject: [PATCH] Rename maxLineLength to softWrapColumn --- spec/app/editor-spec.coffee | 16 ++++++++-------- spec/app/renderer-spec.coffee | 12 ++++++------ src/app/editor.coffee | 22 +++++++++++----------- src/app/renderer.coffee | 18 +++++++++--------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index fbc9c4498..cb0be8ded 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -384,7 +384,7 @@ describe "Editor", -> setEditorHeightInLines(editor, 20) setEditorWidthInChars(editor, 50) editor.setSoftWrap(true) - expect(editor.renderer.maxLineLength).toBe 50 + expect(editor.renderer.softWrapColumn).toBe 50 it "wraps lines that are too long to fit within the editor's width, adjusting cursor positioning accordingly", -> expect(editor.renderedLines.find('.line').length).toBe 16 @@ -427,9 +427,9 @@ describe "Editor", -> editor.toggleSoftWrap() expect(editor.renderedLines.find('.line:eq(3)').text()).toBe ' var pivot = items.shift(), current, left = [], right = [];' - spyOn(editor, 'setMaxLineLength') + spyOn(editor, 'setSoftWrapColumn') $(window).trigger 'resize' - expect(editor.setMaxLineLength).not.toHaveBeenCalled() + expect(editor.setSoftWrapColumn).not.toHaveBeenCalled() it "allows the cursor to move down to the last line", -> _.times editor.getLastScreenRow(), -> editor.moveCursorDown() @@ -453,15 +453,15 @@ describe "Editor", -> editor.moveCursorRight() expect(editor.getCursorScreenPosition()).toEqual [11, 0] - it "calls .setMaxLineLength() when the editor is attached because now its dimensions are available to calculate it", -> + it "calls .setSoftWrapColumn() when the editor is attached because now its dimensions are available to calculate it", -> otherEditor = new Editor() - spyOn(otherEditor, 'setMaxLineLength') + spyOn(otherEditor, 'setSoftWrapColumn') otherEditor.setSoftWrap(true) - expect(otherEditor.setMaxLineLength).not.toHaveBeenCalled() + expect(otherEditor.setSoftWrapColumn).not.toHaveBeenCalled() otherEditor.simulateDomAttachment() - expect(otherEditor.setMaxLineLength).toHaveBeenCalled() + expect(otherEditor.setSoftWrapColumn).toHaveBeenCalled() describe "when some lines at the end of the buffer are not visible on screen", -> beforeEach -> @@ -760,7 +760,7 @@ describe "Editor", -> describe "when wrapping is on", -> it "renders a • instead of line number for wrapped portions of lines", -> - editor.setMaxLineLength(50) + editor.setSoftWrapColumn(50) expect(editor.gutter.find('.line-number').length).toEqual(8) expect(editor.gutter.find('.line-number:eq(3)').text()).toBe '4' expect(editor.gutter.find('.line-number:eq(4)').text()).toBe '•' diff --git a/spec/app/renderer-spec.coffee b/spec/app/renderer-spec.coffee index 5225d2386..a064a74b0 100644 --- a/spec/app/renderer-spec.coffee +++ b/spec/app/renderer-spec.coffee @@ -19,7 +19,7 @@ describe "Renderer", -> describe "soft wrapping", -> beforeEach -> - renderer.setMaxLineLength(50) + renderer.setSoftWrapColumn(50) changeHandler.reset() describe "rendering of soft-wrapped lines", -> @@ -40,7 +40,7 @@ describe "Renderer", -> describe "when there is no whitespace before the boundary", -> it "wraps the line exactly at the boundary since there's no more graceful place to wrap it", -> buffer.change([[0, 0], [1, 0]], 'abcdefghijklmnopqrstuvwxyz\n') - renderer.setMaxLineLength(10) + renderer.setSoftWrapColumn(10) expect(renderer.lineForRow(0).text).toBe 'abcdefghij' expect(renderer.lineForRow(1).text).toBe 'klmnopqrst' expect(renderer.lineForRow(2).text).toBe 'uvwxyz' @@ -128,9 +128,9 @@ describe "Renderer", -> expect(renderer.screenPositionForBufferPosition([4, 5])).toEqual([5, 5]) expect(renderer.bufferPositionForScreenPosition([5, 5])).toEqual([4, 5]) - describe ".setMaxLineLength(length)", -> + describe ".setSoftWrapColumn(length)", -> it "changes the length at which lines are wrapped and emits a change event for all screen lines", -> - renderer.setMaxLineLength(40) + renderer.setSoftWrapColumn(40) expect(tokensText renderer.lineForRow(4).tokens).toBe 'left = [], right = [];' expect(tokensText renderer.lineForRow(5).tokens).toBe ' while(items.length > 0) {' expect(tokensText renderer.lineForRow(12).tokens).toBe 'sort(left).concat(pivot).concat(sort(rig' @@ -151,7 +151,7 @@ describe "Renderer", -> describe "when a foldable line is wrapped", -> it "only marks the first screen line as foldable", -> - renderer.setMaxLineLength(20) + renderer.setSoftWrapColumn(20) expect(renderer.lineForRow(0).foldable).toBeTruthy() expect(renderer.lineForRow(1).foldable).toBeFalsy() expect(renderer.lineForRow(2).foldable).toBeTruthy() @@ -541,7 +541,7 @@ describe "Renderer", -> describe ".clipScreenPosition(screenPosition, wrapBeyondNewlines: false, wrapAtSoftNewlines: false, skipAtomicTokens: false)", -> beforeEach -> - renderer.setMaxLineLength(50) + renderer.setSoftWrapColumn(50) it "allows valid positions", -> expect(renderer.clipScreenPosition([4, 5])).toEqual [4, 5] diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 486d035de..b9c932a4b 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -236,7 +236,7 @@ class Editor extends View @clearRenderedLines() @subscribeToFontSize() @calculateDimensions() - @setMaxLineLength() if @softWrap + @setSoftWrapColumn() if @softWrap @prepareForVerticalScrolling() # this also renders the visible lines @@ -333,7 +333,7 @@ class Editor extends View @trigger 'editor-path-change' @buffer.on "path-change.editor#{@id}", => @trigger 'editor-path-change' - @renderer = new Renderer(@buffer, { maxLineLength: @calcMaxLineLength(), tabText: @tabText }) + @renderer = new Renderer(@buffer, { softWrapColumn: @calcSoftWrapColumn(), tabText: @tabText }) if @attached @prepareForVerticalScrolling() @renderLines() @@ -552,28 +552,28 @@ class Editor extends View toggleSoftWrap: -> @setSoftWrap(not @softWrap) - calcMaxLineLength: -> + calcSoftWrapColumn: -> if @softWrap Math.floor(@scrollView.width() / @charWidth) else Infinity - setMaxLineLength: (maxLineLength) -> - maxLineLength ?= @calcMaxLineLength() - @renderer.setMaxLineLength(maxLineLength) if maxLineLength + setSoftWrapColumn: (softWrapColumn) -> + softWrapColumn ?= @calcSoftWrapColumn() + @renderer.setSoftWrapColumn(softWrapColumn) if softWrapColumn createFold: (startRow, endRow) -> @renderer.createFold(startRow, endRow) - setSoftWrap: (@softWrap, maxLineLength=undefined) -> - @setMaxLineLength(maxLineLength) if @attached + setSoftWrap: (@softWrap, softWrapColumn=undefined) -> + @setSoftWrapColumn(softWrapColumn) if @attached if @softWrap @addClass 'soft-wrap' - @_setMaxLineLength = => @setMaxLineLength() - $(window).on 'resize', @_setMaxLineLength + @_setSoftWrapColumn = => @setSoftWrapColumn() + $(window).on 'resize', @_setSoftWrapColumn else @removeClass 'soft-wrap' - $(window).off 'resize', @_setMaxLineLength + $(window).off 'resize', @_setSoftWrapColumn save: -> if not @buffer.getPath() diff --git a/src/app/renderer.coffee b/src/app/renderer.coffee index 53d906aa3..b5c5e70c7 100644 --- a/src/app/renderer.coffee +++ b/src/app/renderer.coffee @@ -25,7 +25,7 @@ class Renderer @highlighter = new Highlighter(@buffer, options.tabText ? ' ') @lineCommenter = new LineCommenter(@highlighter) @foldSuggester = new FoldSuggester(@highlighter) - @maxLineLength = options.maxLineLength ? Infinity + @softWrapColumn = options.softWrapColumn ? Infinity @activeFolds = {} @foldsById = {} @buildLineMap() @@ -36,7 +36,7 @@ class Renderer @lineMap = new LineMap @lineMap.insertAtBufferRow 0, @buildLinesForBufferRows(0, @buffer.getLastRow()) - setMaxLineLength: (@maxLineLength) -> + setSoftWrapColumn: (@softWrapColumn) -> oldRange = @rangeForAllLines() @buildLineMap() newRange = @rangeForAllLines() @@ -206,7 +206,7 @@ class Renderer startBufferColumn ?= 0 screenLine = screenLine.splitAt(startBufferColumn)[1] if startBufferColumn > 0 - wrapScreenColumn = @findWrapColumn(screenLine.text, @maxLineLength) + wrapScreenColumn = @findWrapColumn(screenLine.text, @softWrapColumn) if wrapScreenColumn? screenLine = screenLine.splitAt(wrapScreenColumn)[0] screenLine.screenDelta = new Point(1, 0) @@ -219,19 +219,19 @@ class Renderer lineFragments - findWrapColumn: (line, maxLineLength) -> - return unless line.length > maxLineLength + findWrapColumn: (line, softWrapColumn) -> + return unless line.length > softWrapColumn - if /\s/.test(line[maxLineLength]) + if /\s/.test(line[softWrapColumn]) # search forward for the start of a word past the boundary - for column in [maxLineLength..line.length] + for column in [softWrapColumn..line.length] return column if /\S/.test(line[column]) return line.length else # search backward for the start of the word on the boundary - for column in [maxLineLength..0] + for column in [softWrapColumn..0] return column + 1 if /\s/.test(line[column]) - return maxLineLength + return softWrapColumn expandScreenRangeToLineEnds: (screenRange) -> screenRange = Range.fromObject(screenRange)