diff --git a/spec/atom/line-map-spec.coffee b/spec/atom/line-map-spec.coffee index 1e89ebfb1..52e8bf3ad 100644 --- a/spec/atom/line-map-spec.coffee +++ b/spec/atom/line-map-spec.coffee @@ -1,6 +1,6 @@ LineMap = require 'line-map' ScreenLineFragment = require 'screen-line-fragment' -Input = require 'buffer' +Buffer = require 'buffer' Highlighter = require 'highlighter' Point = require 'point' @@ -9,205 +9,205 @@ describe "LineMap", -> [line0, line1, line2, line3, line4] = [] beforeEach -> - buffer = new Input(require.resolve 'fixtures/sample.js') + buffer = new Buffer(require.resolve 'fixtures/sample.js') highlighter = new Highlighter(buffer) map = new LineMap [line0, line1, line2, line3, line4] = highlighter.linesForScreenRows(0, 4) - describe ".insertAtInputRow(row, lineFragments)", -> + describe ".insertAtBufferRow(row, lineFragments)", -> it "inserts the given line fragments before the specified buffer row", -> - map.insertAtInputRow(0, [line2, line3]) - map.insertAtInputRow(0, [line0, line1]) - map.insertAtInputRow(4, [line4]) + map.insertAtBufferRow(0, [line2, line3]) + map.insertAtBufferRow(0, [line0, line1]) + map.insertAtBufferRow(4, [line4]) - expect(map.lineForOutputRow(0)).toEqual line0 - expect(map.lineForOutputRow(1)).toEqual line1 - expect(map.lineForOutputRow(2)).toEqual line2 - expect(map.lineForOutputRow(3)).toEqual line3 - expect(map.lineForOutputRow(4)).toEqual line4 + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line1 + expect(map.lineForScreenRow(2)).toEqual line2 + expect(map.lineForScreenRow(3)).toEqual line3 + expect(map.lineForScreenRow(4)).toEqual line4 it "allows for partial line fragments on the row following the insertion", -> [line0a, line0b] = line0.splitAt(10) - map.insertAtInputRow(0, [line0a, line0b]) - map.insertAtInputRow(0, [line1]) + map.insertAtBufferRow(0, [line0a, line0b]) + map.insertAtBufferRow(0, [line1]) - expect(map.lineForOutputRow(0)).toEqual line1 - expect(map.lineForOutputRow(1)).toEqual line0a.concat(line0b) + expect(map.lineForScreenRow(0)).toEqual line1 + expect(map.lineForScreenRow(1)).toEqual line0a.concat(line0b) - describe ".spliceAtInputRow(bufferRow, rowCount, lineFragments)", -> + describe ".spliceAtBufferRow(bufferRow, rowCount, lineFragments)", -> describe "when called with a row count of 0", -> it "inserts the given line fragments before the specified buffer row", -> - map.insertAtInputRow(0, [line0, line1]) - map.spliceAtInputRow(1, 0, [line3, line4]) + map.insertAtBufferRow(0, [line0, line1]) + map.spliceAtBufferRow(1, 0, [line3, line4]) - expect(map.lineForOutputRow(0)).toEqual line0 - expect(map.lineForOutputRow(1)).toEqual line3 - expect(map.lineForOutputRow(2)).toEqual line4 - expect(map.lineForOutputRow(3)).toEqual line1 + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line3 + expect(map.lineForScreenRow(2)).toEqual line4 + expect(map.lineForScreenRow(3)).toEqual line1 - map.spliceAtInputRow(0, 0, [line2]) - expect(map.lineForOutputRow(0)).toEqual line2 + map.spliceAtBufferRow(0, 0, [line2]) + expect(map.lineForScreenRow(0)).toEqual line2 describe "when called with a row count of 1", -> describe "when the specified buffer row is spanned by a single line fragment", -> it "replaces the spanning line fragment with the given line fragments", -> - map.insertAtInputRow(0, [line0, line1, line2]) - map.spliceAtInputRow(1, 1, [line3, line4]) + map.insertAtBufferRow(0, [line0, line1, line2]) + map.spliceAtBufferRow(1, 1, [line3, line4]) - expect(map.inputLineCount()).toBe 4 - expect(map.lineForOutputRow(0)).toEqual line0 - expect(map.lineForOutputRow(1)).toEqual line3 - expect(map.lineForOutputRow(2)).toEqual line4 - expect(map.lineForOutputRow(3)).toEqual line2 + expect(map.bufferLineCount()).toBe 4 + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line3 + expect(map.lineForScreenRow(2)).toEqual line4 + expect(map.lineForScreenRow(3)).toEqual line2 - map.spliceAtInputRow(2, 1, [line0]) - expect(map.lineForOutputRow(2)).toEqual line0 - expect(map.lineForOutputRow(3)).toEqual line2 + map.spliceAtBufferRow(2, 1, [line0]) + expect(map.lineForScreenRow(2)).toEqual line0 + expect(map.lineForScreenRow(3)).toEqual line2 describe "when the specified buffer row is spanned by multiple line fragments", -> it "replaces all spanning line fragments with the given line fragments", -> [line1a, line1b] = line1.splitAt(10) [line3a, line3b] = line3.splitAt(10) - map.insertAtInputRow(0, [line0, line1a, line1b, line2]) - map.spliceAtInputRow(1, 1, [line3a, line3b, line4]) + map.insertAtBufferRow(0, [line0, line1a, line1b, line2]) + map.spliceAtBufferRow(1, 1, [line3a, line3b, line4]) - expect(map.inputLineCount()).toBe 4 - expect(map.lineForOutputRow(0)).toEqual line0 - expect(map.lineForOutputRow(1)).toEqual line3a.concat(line3b) - expect(map.lineForOutputRow(2)).toEqual line4 - expect(map.lineForOutputRow(3)).toEqual line2 + expect(map.bufferLineCount()).toBe 4 + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line3a.concat(line3b) + expect(map.lineForScreenRow(2)).toEqual line4 + expect(map.lineForScreenRow(3)).toEqual line2 describe "when the row following the specified buffer row is spanned by multiple line fragments", -> it "replaces the specified row, but no portion of the following row", -> [line3a, line3b] = line3.splitAt(10) - map.insertAtInputRow(0, [line0, line1, line2, line3a, line3b]) - map.spliceAtInputRow(2, 1, [line4]) + map.insertAtBufferRow(0, [line0, line1, line2, line3a, line3b]) + map.spliceAtBufferRow(2, 1, [line4]) - expect(map.lineForOutputRow(0)).toEqual line0 - expect(map.lineForOutputRow(1)).toEqual line1 - expect(map.lineForOutputRow(2)).toEqual line4 - expect(map.lineForOutputRow(3)).toEqual line3a.concat(line3b) + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line1 + expect(map.lineForScreenRow(2)).toEqual line4 + expect(map.lineForScreenRow(3)).toEqual line3a.concat(line3b) describe "when called with a row count greater than 1", -> it "replaces all line fragments spanning the multiple buffer rows with the given line fragments", -> [line1a, line1b] = line1.splitAt(10) [line3a, line3b] = line3.splitAt(10) - map.insertAtInputRow(0, [line0, line1a, line1b, line2]) - map.spliceAtInputRow(1, 2, [line3a, line3b, line4]) + map.insertAtBufferRow(0, [line0, line1a, line1b, line2]) + map.spliceAtBufferRow(1, 2, [line3a, line3b, line4]) - expect(map.inputLineCount()).toBe 3 - expect(map.lineForOutputRow(0)).toEqual line0 - expect(map.lineForOutputRow(1)).toEqual line3a.concat(line3b) - expect(map.lineForOutputRow(2)).toEqual line4 + expect(map.bufferLineCount()).toBe 3 + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line3a.concat(line3b) + expect(map.lineForScreenRow(2)).toEqual line4 - describe ".spliceAtOutputRow(startRow, rowCount, lineFragemnts)", -> + describe ".spliceAtScreenRow(startRow, rowCount, lineFragemnts)", -> describe "when called with a row count of 0", -> it "inserts the given line fragments before the specified buffer row", -> - map.insertAtInputRow(0, [line0, line1, line2]) - map.spliceAtOutputRow(1, 0, [line3, line4]) + map.insertAtBufferRow(0, [line0, line1, line2]) + map.spliceAtScreenRow(1, 0, [line3, line4]) - expect(map.lineForOutputRow(0)).toEqual line0 - expect(map.lineForOutputRow(1)).toEqual line3 - expect(map.lineForOutputRow(2)).toEqual line4 - expect(map.lineForOutputRow(3)).toEqual line1 - expect(map.lineForOutputRow(4)).toEqual line2 + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line3 + expect(map.lineForScreenRow(2)).toEqual line4 + expect(map.lineForScreenRow(3)).toEqual line1 + expect(map.lineForScreenRow(4)).toEqual line2 describe "when called with a row count of 1", -> - describe "when the specified output row is spanned by a single line fragment", -> + describe "when the specified screen row is spanned by a single line fragment", -> it "replaces the spanning line fragment with the given line fragments", -> - map.insertAtInputRow(0, [line0, line1, line2]) - map.spliceAtOutputRow(1, 1, [line3, line4]) + map.insertAtBufferRow(0, [line0, line1, line2]) + map.spliceAtScreenRow(1, 1, [line3, line4]) - expect(map.inputLineCount()).toBe 4 - expect(map.lineForOutputRow(0)).toEqual line0 - expect(map.lineForOutputRow(1)).toEqual line3 - expect(map.lineForOutputRow(2)).toEqual line4 - expect(map.lineForOutputRow(3)).toEqual line2 + expect(map.bufferLineCount()).toBe 4 + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line3 + expect(map.lineForScreenRow(2)).toEqual line4 + expect(map.lineForScreenRow(3)).toEqual line2 - describe "when the specified output row is spanned by multiple line fragments", -> + describe "when the specified screen row is spanned by multiple line fragments", -> it "replaces all spanning line fragments with the given line fragments", -> [line0a, line0b] = line0.splitAt(10) [line3a, line3b] = line3.splitAt(10) - map.insertAtInputRow(0, [line0a, line0b, line1, line2]) - map.spliceAtOutputRow(0, 1, [line3a, line3b, line4]) + map.insertAtBufferRow(0, [line0a, line0b, line1, line2]) + map.spliceAtScreenRow(0, 1, [line3a, line3b, line4]) - expect(map.inputLineCount()).toBe 4 - expect(map.lineForOutputRow(0)).toEqual line3a.concat(line3b) - expect(map.lineForOutputRow(1)).toEqual line4 - expect(map.lineForOutputRow(2)).toEqual line1 - expect(map.lineForOutputRow(3)).toEqual line2 + expect(map.bufferLineCount()).toBe 4 + expect(map.lineForScreenRow(0)).toEqual line3a.concat(line3b) + expect(map.lineForScreenRow(1)).toEqual line4 + expect(map.lineForScreenRow(2)).toEqual line1 + expect(map.lineForScreenRow(3)).toEqual line2 describe "when called with a row count greater than 1", -> it "replaces all line fragments spanning the multiple buffer rows with the given line fragments", -> [line1a, line1b] = line1.splitAt(10) [line3a, line3b] = line3.splitAt(10) - map.insertAtInputRow(0, [line0, line1a, line1b, line2]) - map.spliceAtOutputRow(1, 2, [line3a, line3b, line4]) + map.insertAtBufferRow(0, [line0, line1a, line1b, line2]) + map.spliceAtScreenRow(1, 2, [line3a, line3b, line4]) - expect(map.inputLineCount()).toBe 3 - expect(map.lineForOutputRow(0)).toEqual line0 - expect(map.lineForOutputRow(1)).toEqual line3a.concat(line3b) - expect(map.lineForOutputRow(2)).toEqual line4 + expect(map.bufferLineCount()).toBe 3 + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line3a.concat(line3b) + expect(map.lineForScreenRow(2)).toEqual line4 - describe ".linesForOutputRows(startRow, endRow)", -> - it "returns lines for the given row range, concatenating fragments that belong on a single output line", -> + describe ".linesForScreenRows(startRow, endRow)", -> + it "returns lines for the given row range, concatenating fragments that belong on a single screen line", -> [line1a, line1b] = line1.splitAt(11) [line3a, line3b] = line3.splitAt(16) - map.insertAtInputRow(0, [line0, line1a, line1b, line2, line3a, line3b, line4]) - expect(map.linesForOutputRows(1, 3)).toEqual [line1, line2, line3] + map.insertAtBufferRow(0, [line0, line1a, line1b, line2, line3a, line3b, line4]) + expect(map.linesForScreenRows(1, 3)).toEqual [line1, line2, line3] # repeating assertion to cover a regression where this method mutated lines - expect(map.linesForOutputRows(1, 3)).toEqual [line1, line2, line3] + expect(map.linesForScreenRows(1, 3)).toEqual [line1, line2, line3] - describe ".lineForInputRow(bufferRow)", -> - it "returns the concatenated output line fragments that comprise the given buffer row", -> + describe ".lineForBufferRow(bufferRow)", -> + it "returns the concatenated screen line fragments that comprise the given buffer row", -> line1Text = line1.text [line1a, line1b] = line1.splitAt(11) - line1a.outputDelta = new Point(1, 0) + line1a.screenDelta = new Point(1, 0) - map.insertAtInputRow(0, [line0, line1a, line1b, line2]) + map.insertAtBufferRow(0, [line0, line1a, line1b, line2]) - expect(map.lineForInputRow(0).text).toBe line0.text - expect(map.lineForInputRow(1).text).toBe line1Text + expect(map.lineForBufferRow(0).text).toBe line0.text + expect(map.lineForBufferRow(1).text).toBe line1Text - describe ".outputPositionForInputPosition(bufferPosition)", -> + describe ".screenPositionForBufferPosition(bufferPosition)", -> beforeEach -> # line1a-line3b describes a fold [line1a, line1b] = line1.splitAt(10) [line3a, line3b] = line3.splitAt(20) - line1a.inputDelta.row = 2 - line1a.inputDelta.column = 20 + line1a.bufferDelta.row = 2 + line1a.bufferDelta.column = 20 # line4a-line4b describes a wrapped line [line4a, line4b] = line4.splitAt(20) - line4a.outputDelta = new Point(1, 0) + line4a.screenDelta = new Point(1, 0) - map.insertAtInputRow(0, [line0, line1a, line3b, line4a, line4b]) + map.insertAtBufferRow(0, [line0, line1a, line3b, line4a, line4b]) - it "translates the given buffer position based on buffer and output deltas of the line fragments in the map", -> - expect(map.outputPositionForInputPosition([0, 0])).toEqual [0, 0] - expect(map.outputPositionForInputPosition([0, 5])).toEqual [0, 5] - expect(map.outputPositionForInputPosition([1, 5])).toEqual [1, 5] - expect(map.outputPositionForInputPosition([3, 20])).toEqual [1, 10] - expect(map.outputPositionForInputPosition([3, 30])).toEqual [1, 20] - expect(map.outputPositionForInputPosition([4, 5])).toEqual [2, 5] + it "translates the given buffer position based on buffer and screen deltas of the line fragments in the map", -> + expect(map.screenPositionForBufferPosition([0, 0])).toEqual [0, 0] + expect(map.screenPositionForBufferPosition([0, 5])).toEqual [0, 5] + expect(map.screenPositionForBufferPosition([1, 5])).toEqual [1, 5] + expect(map.screenPositionForBufferPosition([3, 20])).toEqual [1, 10] + expect(map.screenPositionForBufferPosition([3, 30])).toEqual [1, 20] + expect(map.screenPositionForBufferPosition([4, 5])).toEqual [2, 5] - it "wraps buffer positions at the end of a output line to the end end of the next output line", -> - expect(map.outputPositionForInputPosition([4, 20])).toEqual [3, 0] + it "wraps buffer positions at the end of a screen line to the end end of the next screen line", -> + expect(map.screenPositionForBufferPosition([4, 20])).toEqual [3, 0] - describe ".outputLineCount()", -> - it "returns the total of all inserted output row deltas", -> + describe ".screenLineCount()", -> + it "returns the total of all inserted screen row deltas", -> [line1a, line1b] = line1.splitAt(10) [line3a, line3b] = line3.splitAt(10) - line1a.outputDelta = new Point(1, 0) - line3a.outputDelta = new Point(1, 0) + line1a.screenDelta = new Point(1, 0) + line3a.screenDelta = new Point(1, 0) - map.insertAtInputRow(0, [line0, line1a, line1b, line2]) + map.insertAtBufferRow(0, [line0, line1a, line1b, line2]) - expect(map.outputLineCount()).toBe 4 + expect(map.screenLineCount()).toBe 4 diff --git a/spec/atom/screen-line-fragment-spec.coffee b/spec/atom/screen-line-fragment-spec.coffee index acd1ea0a4..ba52797a8 100644 --- a/spec/atom/screen-line-fragment-spec.coffee +++ b/spec/atom/screen-line-fragment-spec.coffee @@ -31,38 +31,38 @@ describe "screenLineFragment", -> it "ensures the returned fragments cover the span of the original line", -> [left, right] = screenLine.splitAt(15) - expect(left.inputDelta).toEqual [0, 15] - expect(left.outputDelta).toEqual [0, 15] + expect(left.bufferDelta).toEqual [0, 15] + expect(left.screenDelta).toEqual [0, 15] - expect(right.inputDelta).toEqual [1, 0] - expect(right.outputDelta).toEqual [1, 0] + expect(right.bufferDelta).toEqual [1, 0] + expect(right.screenDelta).toEqual [1, 0] [left2, right2] = left.splitAt(5) - expect(left2.inputDelta).toEqual [0, 5] - expect(left2.outputDelta).toEqual [0, 5] + expect(left2.bufferDelta).toEqual [0, 5] + expect(left2.screenDelta).toEqual [0, 5] - expect(right2.inputDelta).toEqual [0, 10] - expect(right2.outputDelta).toEqual [0, 10] + expect(right2.bufferDelta).toEqual [0, 10] + expect(right2.screenDelta).toEqual [0, 10] describe "if splitting at 0", -> it "returns an empty line fragment for the left half", -> left = screenLine.splitAt(0)[0] expect(left.text).toBe '' expect(left.tokens).toEqual [] - expect(left.inputDelta).toEqual [0, 0] - expect(left.outputDelta).toEqual [0, 0] + expect(left.bufferDelta).toEqual [0, 0] + expect(left.screenDelta).toEqual [0, 0] describe "if splitting at a column equal to the line length", -> it "returns an empty line fragment that spans a row for the right half", -> [left, right] = screenLine.splitAt(screenLine.text.length) expect(left.text).toBe screenLine.text - expect(left.outputDelta).toEqual [0, screenLine.text.length] - expect(left.inputDelta).toEqual [0, screenLine.text.length] + expect(left.screenDelta).toEqual [0, screenLine.text.length] + expect(left.bufferDelta).toEqual [0, screenLine.text.length] expect(right.text).toBe '' - expect(right.outputDelta).toEqual [1, 0] - expect(right.inputDelta).toEqual [1, 0] + expect(right.screenDelta).toEqual [1, 0] + expect(right.bufferDelta).toEqual [1, 0] describe ".concat(otherFragment)", -> it "returns the concatenation of the receiver and the given fragment", -> @@ -72,8 +72,8 @@ describe "screenLineFragment", -> concatenated = screenLine.concat(highlighter.lineForScreenRow(4)) expect(concatenated.text).toBe ' var pivot = items.shift(), current, left = [], right = []; while(items.length > 0) {' expect(tokensText concatenated.tokens).toBe concatenated.text - expect(concatenated.outputDelta).toEqual [2, 0] - expect(concatenated.inputDelta).toEqual [2, 0] + expect(concatenated.screenDelta).toEqual [2, 0] + expect(concatenated.bufferDelta).toEqual [2, 0] diff --git a/src/atom/line-map.coffee b/src/atom/line-map.coffee index 2e9756edb..4e93158d3 100644 --- a/src/atom/line-map.coffee +++ b/src/atom/line-map.coffee @@ -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 diff --git a/src/atom/renderer.coffee b/src/atom/renderer.coffee index e24193ade..e7ccd6492 100644 --- a/src/atom/renderer.coffee +++ b/src/atom/renderer.coffee @@ -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])) diff --git a/src/atom/screen-line-fragment.coffee b/src/atom/screen-line-fragment.coffee index 7ecf3c988..30c546baa 100644 --- a/src/atom/screen-line-fragment.coffee +++ b/src/atom/screen-line-fragment.coffee @@ -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)