From 14fc741b4282e60f48da62758ad2a2204a50b374 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 21 Feb 2012 23:36:11 -0700 Subject: [PATCH] Eliminate @index from LineWrapper plus :lipstick: LineWrapper only uses LineMap now --- src/atom/line-wrapper.coffee | 45 +++++++++--------------------------- src/atom/selection.coffee | 2 +- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/atom/line-wrapper.coffee b/src/atom/line-wrapper.coffee index 79353eb70..d434d44d6 100644 --- a/src/atom/line-wrapper.coffee +++ b/src/atom/line-wrapper.coffee @@ -16,11 +16,11 @@ class LineWrapper setMaxLength: (@maxLength) -> oldRange = new Range oldRange.end.row = @screenLineCount() - 1 - oldRange.end.column = _.last(@index.last().screenLines).text.length + oldRange.end.column = @lineMap.lineForScreenRow(oldRange.end.row).text.length @buildWrappedLines() newRange = new Range newRange.end.row = @screenLineCount() - 1 - newRange.end.column = _.last(@index.last().screenLines).text.length + newRange.end.column = @lineMap.lineForScreenRow(newRange.end.row).text.length @trigger 'change', { oldRange, newRange } getSpans: (wrappedLines) -> @@ -30,37 +30,24 @@ class LineWrapper _.flatten(_.pluck(wrappedLines, 'screenLines')) buildWrappedLines: -> - @index = new SpanIndex @lineMap = new LineMap wrappedLines = @buildWrappedLinesForBufferRows(0, @buffer.lastRow()) - @index.insert 0, @getSpans(wrappedLines), wrappedLines @lineMap.insertAtBufferRow 0, @unpackWrappedLines(wrappedLines) handleChange: (e) -> - oldRange = new Range - - bufferRow = e.oldRange.start.row - oldRange.start.row = @firstScreenRowForBufferRow(e.oldRange.start.row) - oldRange.end.row = @lastScreenRowForBufferRow(e.oldRange.end.row) - oldRange.end.column = _.last(@index.at(e.oldRange.end.row).screenLines).text.length + oldScreenRange = @lineMap.screenRangeForBufferRange(@expandRangeToLineEnds(e.oldRange)) { start, end } = e.oldRange wrappedLines = @buildWrappedLinesForBufferRows(e.newRange.start.row, e.newRange.end.row) - @index.splice start.row, end.row, @getSpans(wrappedLines), wrappedLines @lineMap.replaceBufferRows start.row, end.row, @unpackWrappedLines(wrappedLines) - newRange = oldRange.copy() - newRange.end.row = @lastScreenRowForBufferRow(e.newRange.end.row) - newRange.end.column = _.last(@index.at(e.newRange.end.row).screenLines).text.length + newScreenRange = @lineMap.screenRangeForBufferRange(@expandRangeToLineEnds(e.newRange)) - @trigger 'change', { oldRange, newRange } + @trigger 'change', { oldRange: oldScreenRange, newRange: newScreenRange } - firstScreenRowForBufferRow: (bufferRow) -> - @screenPositionForBufferPosition([bufferRow, 0]).row - - lastScreenRowForBufferRow: (bufferRow) -> - startRow = @screenPositionForBufferPosition([bufferRow, 0]).row - startRow + (@index.at(bufferRow).screenLines.length - 1) + expandRangeToLineEnds: (bufferRange) -> + { start, end } = bufferRange + new Range([start.row, 0], [end.row, @lineMap.lineForBufferRow(end.row).text.length]) buildWrappedLinesForBufferRows: (start, end) -> for row in [start..end] @@ -100,10 +87,8 @@ class LineWrapper return column + 1 if /\s/.test(line[column]) return @maxLength - screenRangeFromBufferRange: (bufferRange) -> - start = @screenPositionForBufferPosition(bufferRange.start, false) - end = @screenPositionForBufferPosition(bufferRange.end, false) - new Range(start,end) + screenRangeForBufferRange: (bufferRange) -> + @lineMap.screenRangeForBufferRange(bufferRange) screenPositionForBufferPosition: (bufferPosition, eagerWrap=true) -> @lineMap.screenPositionForBufferPosition(bufferPosition, eagerWrap) @@ -115,15 +100,7 @@ class LineWrapper @screenLinesForRows(screenRow, screenRow)[0] screenLinesForRows: (startRow, endRow) -> - screenLines = [] - - { values, startOffset, endOffset } = @index.sliceBySpan(startRow, endRow) - - screenLines.push(values[0].screenLines[startOffset..-1]...) - for wrappedLine in values[1...-1] - screenLines.push(wrappedLine.screenLines...) - screenLines.push(_.last(values).screenLines[0..endOffset]...) - screenLines + @lineMap.linesForScreenRows(startRow, endRow) screenLines: -> @screenLinesForRows(0, @screenLineCount() - 1) diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index b4eaa02be..0efa856be 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -71,7 +71,7 @@ class Selection extends View @cursor.setPosition(range.end) getScreenRange: -> - @editor.lineWrapper.screenRangeFromBufferRange(@getRange()) + @editor.lineWrapper.screenRangeForBufferRange(@getRange()) getText: -> @editor.buffer.getTextInRange @getRange()