Gutter renders correctly with line wrapping and folds

This commit is contained in:
Nathan Sobo
2012-03-07 12:19:30 -07:00
parent 20deb80d9f
commit 461dd5cd37
6 changed files with 50 additions and 7 deletions

View File

@@ -215,8 +215,8 @@ class Editor extends View
toggleSoftWrap: ->
@setSoftWrap(not @softWrap)
setMaxLineLength: ->
maxLength =
setMaxLineLength: (maxLength) ->
maxLength ?=
if @softWrap
Math.floor(@lines.width() / @charWidth)
else
@@ -259,6 +259,9 @@ class Editor extends View
bufferRangeForScreenRange: (range) ->
@renderer.bufferRangeForScreenRange(range)
bufferRowsForScreenRows: ->
@renderer.bufferRowsForScreenRows()
screenPositionFromMouseEvent: (e) ->
{ pageX, pageY } = e
@screenPositionFromPixelPosition
@@ -347,3 +350,6 @@ class Editor extends View
fold = @renderer.foldsById[foldId]
fold.destroy()
@setCursorBufferPosition(fold.start)
logLines: ->
@renderer.logLines()

View File

@@ -8,8 +8,11 @@ class Gutter extends View
@content: ->
@div class: 'gutter'
renderLineNumbers: (screenLines) ->
renderLineNumbers: ->
@empty()
for screenLine, i in screenLines
lastRow = -1
for row in @parentView.bufferRowsForScreenRows()
@append $$ ->
@div {class: 'line-number'}, i + 1
@div {class: 'line-number'}, if row == lastRow then '' else row + 1
lastRow = row

View File

@@ -37,6 +37,15 @@ class LineMap
linesForBufferRows: (startRow, endRow) ->
@linesByDelta('bufferDelta', startRow, endRow)
bufferRowsForScreenRows: (startRow, endRow=@lastScreenRow())->
bufferRows = []
currentScreenRow = -1
@traverseByDelta 'screenDelta', [startRow, 0], [endRow, 0], ({ screenDelta, bufferDelta }) ->
bufferRows.push(bufferDelta.row) if screenDelta.row > currentScreenRow
currentScreenRow = screenDelta.row
bufferRows
bufferLineCount: ->
@lineCountByDelta('bufferDelta')
@@ -89,7 +98,7 @@ class LineMap
linesByDelta: (deltaType, startRow, endRow) ->
lines = []
pendingFragment = null
@traverseByDelta deltaType, new Point(startRow, 0), new Point(endRow, Infinity), (lineFragment) ->
@traverseByDelta deltaType, new Point(startRow, 0), new Point(endRow, Infinity), ({lineFragment}) ->
if pendingFragment
pendingFragment = pendingFragment.concat(lineFragment)
else
@@ -154,7 +163,7 @@ class LineMap
bufferDelta = new Point
for lineFragment in @lineFragments
iterator(lineFragment) if traversalDelta.isGreaterThanOrEqual(startPosition) and iterator?
iterator({ lineFragment, screenDelta, bufferDelta }) if traversalDelta.isGreaterThanOrEqual(startPosition) and iterator?
traversalDelta = traversalDelta.add(lineFragment[deltaType])
break if traversalDelta.isGreaterThan(endPosition)
screenDelta = screenDelta.add(lineFragment.screenDelta)

View File

@@ -45,6 +45,9 @@ class Renderer
getLines: ->
@lineMap.linesForScreenRows(0, @lineMap.lastScreenRow())
bufferRowsForScreenRows: ->
@lineMap.bufferRowsForScreenRows()
createFold: (bufferRange) ->
bufferRange = Range.fromObject(bufferRange)
return if bufferRange.isEmpty()