From 5bb539df27aafb45c77cff6d4f74a469ed9ddfac Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 22 Feb 2012 17:36:38 -0700 Subject: [PATCH] :lipstick: --- spec/atom/line-map-spec.coffee | 82 +++++++++++++++++----------------- src/atom/editor.coffee | 2 +- src/atom/line-folder.coffee | 6 +++ src/atom/line-map.coffee | 16 +------ src/atom/line-wrapper.coffee | 2 +- 5 files changed, 51 insertions(+), 57 deletions(-) diff --git a/spec/atom/line-map-spec.coffee b/spec/atom/line-map-spec.coffee index 54b341829..13b8143ce 100644 --- a/spec/atom/line-map-spec.coffee +++ b/spec/atom/line-map-spec.coffee @@ -22,10 +22,10 @@ describe "LineMap", -> map.insertAtBufferRow(2, line3) map.insertAtBufferRow(2, line2) - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line1] - expect(map.screenLinesForScreenRow(2)).toEqual [line2] - expect(map.screenLinesForScreenRow(3)).toEqual [line3] + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line1 + expect(map.lineForScreenRow(2)).toEqual line2 + expect(map.lineForScreenRow(3)).toEqual line3 describe "when passed an array of line fragments", -> it "inserts the given line fragments before the specified buffer row", -> @@ -33,11 +33,11 @@ describe "LineMap", -> map.insertAtBufferRow(0, [line0, line1]) map.insertAtBufferRow(4, [line4]) - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line1] - expect(map.screenLinesForScreenRow(2)).toEqual [line2] - expect(map.screenLinesForScreenRow(3)).toEqual [line3] - expect(map.screenLinesForScreenRow(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 describe ".spliceAtBufferRow(bufferRow, rowCount, screenLines)", -> describe "when called with a row count of 0", -> @@ -45,11 +45,11 @@ describe "LineMap", -> map.insertAtBufferRow(0, [line0, line1, line2]) map.spliceAtBufferRow(1, 0, [line3, line4]) - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line3] - expect(map.screenLinesForScreenRow(2)).toEqual [line4] - expect(map.screenLinesForScreenRow(3)).toEqual [line1] - expect(map.screenLinesForScreenRow(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 buffer row is spanned by a single line fragment", -> @@ -58,10 +58,10 @@ describe "LineMap", -> map.spliceAtBufferRow(1, 1, [line3, line4]) expect(map.bufferLineCount()).toBe 4 - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line3] - expect(map.screenLinesForScreenRow(2)).toEqual [line4] - expect(map.screenLinesForScreenRow(3)).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 line2 describe "when the specified buffer row is spanned by multiple line fragments", -> it "replaces all spanning line fragments with the given line fragments", -> @@ -72,10 +72,10 @@ describe "LineMap", -> map.spliceAtBufferRow(1, 1, [line3a, line3b, line4]) expect(map.bufferLineCount()).toBe 4 - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b] - expect(map.screenLinesForScreenRow(2)).toEqual [line4] - expect(map.screenLinesForScreenRow(3)).toEqual [line2] + 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 called with a row count greater than 1", -> it "replaces all line fragments spanning the multiple buffer rows with the given line fragments", -> @@ -86,9 +86,9 @@ describe "LineMap", -> map.spliceAtBufferRow(1, 2, [line3a, line3b, line4]) expect(map.bufferLineCount()).toBe 3 - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b] - expect(map.screenLinesForScreenRow(2)).toEqual [line4] + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line3a.concat(line3b) + expect(map.lineForScreenRow(2)).toEqual line4 describe ".spliceAtScreenRow(startRow, rowCount, lineFragemnts)", -> describe "when called with a row count of 0", -> @@ -96,11 +96,11 @@ describe "LineMap", -> map.insertAtBufferRow(0, [line0, line1, line2]) map.spliceAtScreenRow(1, 0, [line3, line4]) - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line3] - expect(map.screenLinesForScreenRow(2)).toEqual [line4] - expect(map.screenLinesForScreenRow(3)).toEqual [line1] - expect(map.screenLinesForScreenRow(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 screen row is spanned by a single line fragment", -> @@ -109,10 +109,10 @@ describe "LineMap", -> map.spliceAtScreenRow(1, 1, [line3, line4]) expect(map.bufferLineCount()).toBe 4 - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line3] - expect(map.screenLinesForScreenRow(2)).toEqual [line4] - expect(map.screenLinesForScreenRow(3)).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 line2 describe "when the specified screen row is spanned by multiple line fragments", -> it "replaces all spanning line fragments with the given line fragments", -> @@ -123,10 +123,10 @@ describe "LineMap", -> map.spliceAtScreenRow(1, 1, [line3a, line3b, line4]) expect(map.bufferLineCount()).toBe 4 - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b] - expect(map.screenLinesForScreenRow(2)).toEqual [line4] - expect(map.screenLinesForScreenRow(3)).toEqual [line2] + 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 called with a row count greater than 1", -> it "replaces all line fragments spanning the multiple buffer rows with the given line fragments", -> @@ -137,9 +137,9 @@ describe "LineMap", -> map.spliceAtScreenRow(1, 2, [line3a, line3b, line4]) expect(map.bufferLineCount()).toBe 3 - expect(map.screenLinesForScreenRow(0)).toEqual [line0] - expect(map.screenLinesForScreenRow(1)).toEqual [line3a, line3b] - expect(map.screenLinesForScreenRow(2)).toEqual [line4] + expect(map.lineForScreenRow(0)).toEqual line0 + expect(map.lineForScreenRow(1)).toEqual line3a.concat(line3b) + expect(map.lineForScreenRow(2)).toEqual line4 describe ".linesForScreenRows(startRow, endRow)", -> it "returns lines for the given row range, concatenating fragments that belong on a single screen line", -> diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 4fd1fd79d..3c4572ef7 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -129,7 +129,7 @@ class Editor extends View renderLines: -> @lines.empty() - for screenLine in @lineWrapper.lines() + for screenLine in @lineWrapper.getLines() @lines.append @buildLineElement(screenLine) setBuffer: (@buffer) -> diff --git a/src/atom/line-folder.coffee b/src/atom/line-folder.coffee index 7a489c3ed..e54fd5fcb 100644 --- a/src/atom/line-folder.coffee +++ b/src/atom/line-folder.coffee @@ -80,6 +80,12 @@ class LineFolder linesForScreenRows: (startRow, endRow) -> @lineMap.linesForScreenRows(startRow, endRow) + getLines: -> + @lineMap.getScreenLines() + + lineCount: -> + @lineMap.screenLineCount() + screenRowForBufferRow: (bufferRow) -> @screenPositionForBufferPosition([bufferRow, 0]).row diff --git a/src/atom/line-map.coffee b/src/atom/line-map.coffee index 8dc432c05..51984def0 100644 --- a/src/atom/line-map.coffee +++ b/src/atom/line-map.coffee @@ -45,26 +45,14 @@ class LineMap replaceBufferRows: (start, end, screenLines) -> @spliceAtBufferRow(start, end - start + 1, screenLines) - replaceScreenRow: (row, screenLines) -> @replaceScreenRows(row, row, screenLines) replaceScreenRows: (start, end, screenLines) -> @spliceAtScreenRow(start, end - start + 1, screenLines) - screenLinesForScreenRow: (screenRow) -> - @screenLinesForScreenRows(screenRow, screenRow) - - screenLinesForScreenRows: (startRow, endRow) -> - screenLines = [] - delta = new Delta - - for screenLine in @screenLines - break if delta.rows > endRow - screenLines.push(screenLine) if delta.rows >= startRow - delta = delta.add(screenLine.screenDelta) - - screenLines + getScreenLines: -> + return @screenLines lineForScreenRow: (row) -> @linesForScreenRows(row, row)[0] diff --git a/src/atom/line-wrapper.coffee b/src/atom/line-wrapper.coffee index 5c8909caf..9899d1d1a 100644 --- a/src/atom/line-wrapper.coffee +++ b/src/atom/line-wrapper.coffee @@ -92,7 +92,7 @@ class LineWrapper linesForScreenRows: (startRow, endRow) -> @lineMap.linesForScreenRows(startRow, endRow) - lines: -> + getLines: -> @linesForScreenRows(0, @lineCount() - 1) lineCount: ->