Rename maxLineLength to softWrapColumn

This commit is contained in:
Nathan Sobo
2012-06-05 12:38:53 -06:00
parent 4dc41dcc21
commit 911a417cb8
4 changed files with 34 additions and 34 deletions

View File

@@ -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()

View File

@@ -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)