wip: what nathan and corey did

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-05-18 15:15:44 -07:00
parent 4c92be669e
commit 39e02bbf9f
8 changed files with 164 additions and 387 deletions

View File

@@ -522,8 +522,8 @@ class Editor extends View
maxLineLength ?= @calcMaxLineLength()
@renderer.setMaxLineLength(maxLineLength) if maxLineLength
createFold: (range) ->
@renderer.createFold(range)
createFold: (startRow, endRow) ->
@renderer.createFold(startRow, endRow)
setSoftWrap: (@softWrap, maxLineLength=undefined) ->
@setMaxLineLength(maxLineLength) if @attached

View File

@@ -3,49 +3,53 @@ Range = require 'range'
module.exports =
class Fold
@idCounter: 1
start: null
end: null
constructor: (@lineFolder, {@start, @end}) ->
renderer: null
startRow: null
endRow: null
constructor: (@renderer, @startRow, @endRow) ->
@id = @constructor.idCounter++
destroy: ->
@lineFolder.destroyFold(this)
@renderer.destroyFold(this)
getRange: ->
new Range(@start, @end)
# new Range([@startRow, 0], @endRow)
throw "Don't worry about this yet -- sobo"
handleBufferChange: (event) ->
oldStartRow = @start.row
# oldStartRow = @start.row
{ oldRange } = event
if oldRange.start.isLessThanOrEqual(@start) and oldRange.end.isGreaterThanOrEqual(@end)
@lineFolder.unregisterFold(oldStartRow, this)
return
# { oldRange } = event
# if oldRange.start.isLessThanOrEqual(@start) and oldRange.end.isGreaterThanOrEqual(@end)
# @renderer.unregisterFold(oldStartRow, this)
# return
changeInsideFold = @start.isLessThanOrEqual(oldRange.start) and @end.isGreaterThan(oldRange.end)
# changeInsideFold = @start.isLessThanOrEqual(oldRange.start) and @end.isGreaterThan(oldRange.end)
@start = @updateAnchorPoint(@start, event)
@end = @updateAnchorPoint(@end, event, false)
# @start = @updateAnchorPoint(@start, event)
# @end = @updateAnchorPoint(@end, event, false)
if @start.row != oldStartRow
@lineFolder.unregisterFold(oldStartRow, this)
@lineFolder.registerFold(@start.row, this)
# if @start.row != oldStartRow
# @renderer.unregisterFold(oldStartRow, this)
# @lineFolder.registerFold(@start.row, this)
changeInsideFold
# changeInsideFold
updateAnchorPoint: (point, event, inclusive=true) ->
{ newRange, oldRange } = event
if inclusive
return point if oldRange.end.isGreaterThan(point)
else
return point if oldRange.end.isGreaterThanOrEqual(point)
# { newRange, oldRange } = event
# if inclusive
# return point if oldRange.end.isGreaterThan(point)
# else
# return point if oldRange.end.isGreaterThanOrEqual(point)
newRange.end.add(point.subtract(oldRange.end))
# newRange.end.add(point.subtract(oldRange.end))
compare: (other) ->
startComparison = @start.compare(other.start)
if startComparison == 0
other.end.compare(@end)
else
startComparison
other
# startComparison = @start.compare(other.start)
# if startComparison == 0
# other.end.compare(@end)
# else
# startComparison

View File

@@ -51,23 +51,13 @@ class Renderer
bufferRowsForScreenRows: (startRow, endRow) ->
@lineMap.bufferRowsForScreenRows(startRow, endRow)
createFold: (bufferRange) ->
bufferRange = Range.fromObject(bufferRange)
return if bufferRange.isEmpty()
fold = new Fold(this, bufferRange)
@registerFold(bufferRange.start.row, fold)
# If this fold starts on a screen line that contains other folds, we'll
# need to the re-render the screen lines corresponding to these preceding
# folds as well. So we alter the start row of the buffer range we
# are going to change to the buffer row of the first fold in a potential
# series of folds that ends on the current fold's starting buffer row.
bufferRange = bufferRange.copy()
bufferRange.start.row = @bufferRowForScreenRow(@screenRowForBufferRow(bufferRange.start.row))
createFold: (startRow, endRow) ->
fold = new Fold(this, startRow, endRow)
@registerFold(startRow, fold)
bufferRange = new Range([[startRow, 0], [endRow, @buffer.lineLengthForRow(endRow)]])
oldScreenRange = @screenLineRangeForBufferRange(bufferRange)
lines = @buildLineForBufferRow(bufferRange.start.row)
lines = @buildLineForBufferRow(startRow)
@lineMap.replaceScreenRows(oldScreenRange.start.row, oldScreenRange.end.row, lines)
newScreenRange = @screenLineRangeForBufferRange(bufferRange)
@@ -147,29 +137,20 @@ class Renderer
startBufferColumn = null
currentScreenLineLength = 0
loop
break if startBufferRow > endBufferRow and not startBufferColumn?
while startBufferRow <= endBufferRow
break if
startBufferColumn ?= 0
line = @highlighter.lineForRow(startBufferRow)
line = line.splitAt(startBufferColumn)[1]
wrapScreenColumn = @findWrapColumn(line.text, @maxLineLength - currentScreenLineLength)
continueMainLoop = false
for fold in @foldsForBufferRow(startBufferRow)
if fold.start.column >= startBufferColumn
foldStartSceenColumn = fold.start.column - startBufferColumn
if (foldStartSceenColumn) > wrapScreenColumn - foldPlaceholderLength
wrapScreenColumn = Math.min(wrapScreenColumn, foldStartSceenColumn)
break
prefix = line.splitAt(foldStartSceenColumn)[0]
placeholder = @buildFoldPlaceholder(fold)
lineFragments.push(prefix, placeholder)
startBufferRow = fold.end.row
startBufferColumn = fold.end.column
currentScreenLineLength = currentScreenLineLength + (prefix?.text.length ? 0) + foldPlaceholderLength
continueMainLoop = true
break
continue if continueMainLoop
if fold = @foldForBufferRow(startBufferRow)
placeholder = @buildFoldPlaceholder(fold)
lineFragments.push(placeholder)
startBufferRow = fold.end.row + 1
startBufferColumn = 0
currentScreenLineLength = 0
continue
if wrapScreenColumn?
line = line.splitAt(wrapScreenColumn)[0]

View File

@@ -237,5 +237,5 @@ class Selection extends View
fold: ->
range = @getBufferRange()
@editor.createFold(range)
@cursor.setBufferPosition(range.end)
@editor.createFold(range.start.row, range.end.row)
@cursor.setBufferPosition([range.end.row + 1, 0])