Rename input/output to buffer/screen in LineMap

Now that we don't have two translation steps, it's not a lie to refer
to the coordinate spaces being translated by the line map as buffer and
screen
This commit is contained in:
Nathan Sobo
2012-03-06 19:20:28 -07:00
parent da6a708b46
commit 47ee8d599d
5 changed files with 205 additions and 205 deletions

View File

@@ -7,66 +7,66 @@ class LineMap
constructor: ->
@lineFragments = []
insertAtInputRow: (inputRow, lineFragments) ->
@spliceAtInputRow(inputRow, 0, lineFragments)
insertAtBufferRow: (bufferRow, lineFragments) ->
@spliceAtBufferRow(bufferRow, 0, lineFragments)
spliceAtInputRow: (startRow, rowCount, lineFragments) ->
@spliceByDelta('inputDelta', startRow, rowCount, lineFragments)
spliceAtBufferRow: (startRow, rowCount, lineFragments) ->
@spliceByDelta('bufferDelta', startRow, rowCount, lineFragments)
spliceAtOutputRow: (startRow, rowCount, lineFragments) ->
@spliceByDelta('outputDelta', startRow, rowCount, lineFragments)
spliceAtScreenRow: (startRow, rowCount, lineFragments) ->
@spliceByDelta('screenDelta', startRow, rowCount, lineFragments)
replaceInputRows: (start, end, lineFragments) ->
@spliceAtInputRow(start, end - start + 1, lineFragments)
replaceBufferRows: (start, end, lineFragments) ->
@spliceAtBufferRow(start, end - start + 1, lineFragments)
replaceOutputRow: (row, lineFragments) ->
@replaceOutputRows(row, row, lineFragments)
replaceScreenRow: (row, lineFragments) ->
@replaceScreenRows(row, row, lineFragments)
replaceOutputRows: (start, end, lineFragments) ->
@spliceAtOutputRow(start, end - start + 1, lineFragments)
replaceScreenRows: (start, end, lineFragments) ->
@spliceAtScreenRow(start, end - start + 1, lineFragments)
lineForOutputRow: (row) ->
@linesForOutputRows(row, row)[0]
lineForScreenRow: (row) ->
@linesForScreenRows(row, row)[0]
linesForOutputRows: (startRow, endRow) ->
@linesByDelta('outputDelta', startRow, endRow)
linesForScreenRows: (startRow, endRow) ->
@linesByDelta('screenDelta', startRow, endRow)
lineForInputRow: (row) ->
@linesForInputRows(row, row)[0]
lineForBufferRow: (row) ->
@linesForBufferRows(row, row)[0]
linesForInputRows: (startRow, endRow) ->
@linesByDelta('inputDelta', startRow, endRow)
linesForBufferRows: (startRow, endRow) ->
@linesByDelta('bufferDelta', startRow, endRow)
inputLineCount: ->
@lineCountByDelta('inputDelta')
bufferLineCount: ->
@lineCountByDelta('bufferDelta')
outputLineCount: ->
@lineCountByDelta('outputDelta')
screenLineCount: ->
@lineCountByDelta('screenDelta')
lineCountByDelta: (deltaType) ->
@traverseByDelta(deltaType, new Point(Infinity, 0))[deltaType].row
lastOutputRow: ->
@outputLineCount() - 1
lastScreenRow: ->
@screenLineCount() - 1
outputPositionForInputPosition: (inputPosition) ->
@translatePosition('inputDelta', 'outputDelta', inputPosition)
screenPositionForBufferPosition: (bufferPosition) ->
@translatePosition('bufferDelta', 'screenDelta', bufferPosition)
inputPositionForOutputPosition: (outputPosition) ->
@translatePosition('outputDelta', 'inputDelta', outputPosition)
bufferPositionForScreenPosition: (screenPosition) ->
@translatePosition('screenDelta', 'bufferDelta', screenPosition)
outputRangeForInputRange: (inputRange) ->
start = @outputPositionForInputPosition(inputRange.start)
end = @outputPositionForInputPosition(inputRange.end)
screenRangeForBufferRange: (bufferRange) ->
start = @screenPositionForBufferPosition(bufferRange.start)
end = @screenPositionForBufferPosition(bufferRange.end)
new Range(start, end)
inputRangeForOutputRange: (outputRange) ->
start = @inputPositionForOutputPosition(outputRange.start)
end = @inputPositionForOutputPosition(outputRange.end)
bufferRangeForScreenRange: (screenRange) ->
start = @bufferPositionForScreenPosition(screenRange.start)
end = @bufferPositionForScreenPosition(screenRange.end)
new Range(start, end)
clipOutputPosition: (outputPosition, options) ->
@clipPosition('outputDelta', outputPosition, options)
clipScreenPosition: (screenPosition, options) ->
@clipPosition('screenDelta', screenPosition, options)
clipPosition: (deltaType, position, options) ->
@translatePosition(deltaType, deltaType, position, options)
@@ -95,7 +95,7 @@ class LineMap
else
pendingFragment = _.clone(lineFragment)
if pendingFragment[deltaType].row > 0
pendingFragment.inputDelta = new Point(1, 0)
pendingFragment.bufferDelta = new Point(1, 0)
lines.push pendingFragment
pendingFragment = null
lines
@@ -150,20 +150,20 @@ class LineMap
traverseByDelta: (deltaType, startPosition, endPosition=startPosition, iterator=null) ->
traversalDelta = new Point
outputDelta = new Point
inputDelta = new Point
screenDelta = new Point
bufferDelta = new Point
for lineFragment in @lineFragments
iterator(lineFragment) if traversalDelta.isGreaterThanOrEqual(startPosition) and iterator?
traversalDelta = traversalDelta.add(lineFragment[deltaType])
break if traversalDelta.isGreaterThan(endPosition)
outputDelta = outputDelta.add(lineFragment.outputDelta)
inputDelta = inputDelta.add(lineFragment.inputDelta)
screenDelta = screenDelta.add(lineFragment.screenDelta)
bufferDelta = bufferDelta.add(lineFragment.bufferDelta)
{ outputDelta, inputDelta, lastLineFragment: lineFragment }
{ screenDelta, bufferDelta, lastLineFragment: lineFragment }
logLines: (start=0, end=@outputLineCount() - 1)->
logLines: (start=0, end=@screenLineCount() - 1)->
for row in [start..end]
line = @lineForOutputRow(row).text
line = @lineForScreenRow(row).text
console.log row, line, line.length

View File

@@ -28,7 +28,7 @@ class Renderer
buildLineMap: ->
@lineMap = new LineMap
@lineMap.insertAtInputRow 0, @buildLinesForBufferRows(0, @buffer.lastRow())
@lineMap.insertAtBufferRow 0, @buildLinesForBufferRows(0, @buffer.lastRow())
setMaxLineLength: (@maxLineLength) ->
oldRange = @rangeForAllLines()
@@ -37,13 +37,13 @@ class Renderer
@trigger 'change', { oldRange, newRange }
lineForRow: (row) ->
@lineMap.lineForOutputRow(row)
@lineMap.lineForScreenRow(row)
linesForRows: (startRow, endRow) ->
@lineMap.linesForOutputRows(startRow, endRow)
@lineMap.linesForScreenRows(startRow, endRow)
getLines: ->
@lineMap.linesForOutputRows(0, @lineMap.lastOutputRow())
@lineMap.linesForScreenRows(0, @lineMap.lastScreenRow())
createFold: (bufferRange) ->
bufferRange = Range.fromObject(bufferRange)
@@ -54,7 +54,7 @@ class Renderer
oldScreenRange = @screenLineRangeForBufferRange(bufferRange)
lines = @buildLineForBufferRow(bufferRange.start.row)
@lineMap.replaceOutputRows(
@lineMap.replaceScreenRows(
oldScreenRange.start.row,
oldScreenRange.end.row,
lines)
@@ -71,7 +71,7 @@ class Renderer
startScreenRow = @screenRowForBufferRow(bufferRange.start.row)
oldScreenRange = @expandScreenRangeToLineEnds(new Range([startScreenRow, 0], [startScreenRow, 0]))
@lineMap.replaceOutputRow(startScreenRow,
@lineMap.replaceScreenRow(startScreenRow,
@buildLinesForBufferRows(bufferRange.start.row, bufferRange.end.row))
newScreenRange = @screenLineRangeForBufferRange(bufferRange)
@@ -79,19 +79,19 @@ class Renderer
@trigger 'unfold', fold.getRange()
screenRowForBufferRow: (bufferRow) ->
@lineMap.outputPositionForInputPosition([bufferRow, 0]).row
@lineMap.screenPositionForBufferPosition([bufferRow, 0]).row
bufferRowForScreenRow: (screenRow) ->
@lineMap.inputPositionForOutputPosition([screenRow, 0]).row
@lineMap.bufferPositionForScreenPosition([screenRow, 0]).row
screenRangeForBufferRange: (bufferRange) ->
@lineMap.outputRangeForInputRange(bufferRange)
@lineMap.screenRangeForBufferRange(bufferRange)
bufferRangeForScreenRange: (screenRange) ->
@lineMap.inputRangeForOutputRange(screenRange)
@lineMap.bufferRangeForScreenRange(screenRange)
lineCount: ->
@lineMap.outputLineCount()
@lineMap.screenLineCount()
lastRow: ->
@lineCount() - 1
@@ -100,13 +100,13 @@ class Renderer
@lineMap.logLines()
screenPositionForBufferPosition: (position) ->
@lineMap.outputPositionForInputPosition(position)
@lineMap.screenPositionForBufferPosition(position)
bufferPositionForScreenPosition: (position) ->
@lineMap.inputPositionForOutputPosition(position)
@lineMap.bufferPositionForScreenPosition(position)
clipScreenPosition: (position, options={}) ->
@lineMap.clipOutputPosition(position, options)
@lineMap.clipScreenPosition(position, options)
handleBufferChange: (e) ->
for row, folds of @activeFolds
@@ -122,7 +122,7 @@ class Renderer
oldScreenRange = @screenLineRangeForBufferRange(oldBufferRange)
newScreenLines = @buildLinesForBufferRows(newBufferRange.start.row, newBufferRange.end.row)
@lineMap.replaceOutputRows oldScreenRange.start.row, oldScreenRange.end.row, newScreenLines
@lineMap.replaceScreenRows oldScreenRange.start.row, oldScreenRange.end.row, newScreenLines
newScreenRange = @screenLineRangeForBufferRange(newBufferRange)
@trigger 'change', { oldRange: oldScreenRange, newRange: newScreenRange }
@@ -153,7 +153,7 @@ class Renderer
if wrapColumn?
line = line.splitAt(wrapColumn)[0]
line.outputDelta = new Point(1, 0)
line.screenDelta = new Point(1, 0)
[line].concat buildLinesForBufferRows(startRow, endRow, startColumn + wrapColumn)
else
[line].concat buildLinesForBufferRows(startRow + 1, endRow)
@@ -197,16 +197,16 @@ class Renderer
screenLineRangeForBufferRange: (bufferRange) ->
@expandScreenRangeToLineEnds(
@lineMap.outputRangeForInputRange(
@lineMap.screenRangeForBufferRange(
@expandBufferRangeToLineEnds(bufferRange)))
expandScreenRangeToLineEnds: (screenRange) ->
{ start, end } = screenRange
new Range([start.row, 0], [end.row, @lineMap.lineForOutputRow(end.row).text.length])
new Range([start.row, 0], [end.row, @lineMap.lineForScreenRow(end.row).text.length])
expandBufferRangeToLineEnds: (bufferRange) ->
{ start, end } = bufferRange
new Range([start.row, 0], [end.row, @lineMap.lineForInputRow(end.row).text.length])
new Range([start.row, 0], [end.row, @lineMap.lineForBufferRow(end.row).text.length])
rangeForAllLines: ->
new Range([0, 0], @clipScreenPosition([Infinity, Infinity]))

View File

@@ -5,9 +5,9 @@ module.exports =
class ScreenLineFragment
isAtomic: false
constructor: (@tokens, @text, outputDelta, inputDelta, extraFields) ->
@outputDelta = Point.fromObject(outputDelta)
@inputDelta = Point.fromObject(inputDelta)
constructor: (@tokens, @text, screenDelta, bufferDelta, extraFields) ->
@screenDelta = Point.fromObject(screenDelta)
@bufferDelta = Point.fromObject(bufferDelta)
_.extend(this, extraFields)
splitAt: (column) ->
@@ -26,8 +26,8 @@ class ScreenLineFragment
leftText = _.pluck(leftTokens, 'value').join('')
rightText = _.pluck(rightTokens, 'value').join('')
[leftScreenDelta, rightScreenDelta] = @outputDelta.splitAt(column)
[leftBufferDelta, rightBufferDelta] = @inputDelta.splitAt(column)
[leftScreenDelta, rightScreenDelta] = @screenDelta.splitAt(column)
[leftBufferDelta, rightBufferDelta] = @bufferDelta.splitAt(column)
leftFragment = new ScreenLineFragment(leftTokens, leftText, leftScreenDelta, leftBufferDelta)
rightFragment = new ScreenLineFragment(rightTokens, rightText, rightScreenDelta, rightBufferDelta)
@@ -49,9 +49,9 @@ class ScreenLineFragment
concat: (other) ->
tokens = @tokens.concat(other.tokens)
text = @text + other.text
outputDelta = @outputDelta.add(other.outputDelta)
inputDelta = @inputDelta.add(other.inputDelta)
new ScreenLineFragment(tokens, text, outputDelta, inputDelta)
screenDelta = @screenDelta.add(other.screenDelta)
bufferDelta = @bufferDelta.add(other.bufferDelta)
new ScreenLineFragment(tokens, text, screenDelta, bufferDelta)
lengthForClipping: ->
if @isAtomic
@@ -60,7 +60,7 @@ class ScreenLineFragment
@text.length
isSoftWrapped: ->
@outputDelta.row == 1 and @inputDelta.row == 0
@screenDelta.row == 1 and @bufferDelta.row == 0
isEqual: (other) ->
_.isEqual(@tokens, other.tokens) and @outputDelta.isEqual(other.outputDelta) and @inputDelta.isEqual(other.inputDelta)
_.isEqual(@tokens, other.tokens) and @screenDelta.isEqual(other.screenDelta) and @bufferDelta.isEqual(other.bufferDelta)