From 6de6852e922c09b8c2099e18135ee88d06d6b675 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 15 Feb 2012 17:11:06 -0700 Subject: [PATCH] SpanIndex.spanForIndex returns span of elements up to and *including* index. --- spec/atom/span-index-spec.coffee | 17 +++++++++-------- src/atom/line-wrapper.coffee | 4 ++-- src/atom/span-index.coffee | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/spec/atom/span-index-spec.coffee b/spec/atom/span-index-spec.coffee index c103d0603..971dfdde6 100644 --- a/spec/atom/span-index-spec.coffee +++ b/spec/atom/span-index-spec.coffee @@ -22,11 +22,11 @@ describe "SpanIndex", -> it "updates the spans of a range of entries indicated by the given index to the given value", -> index.insert(0, [3, 2, 3, 1, 2], ['a', 'b', 'c', 'd', 'e']) index.updateSpans(1, 3, 1) - expect(index.spanForIndex(1)).toBe 3 - expect(index.spanForIndex(2)).toBe 4 - expect(index.spanForIndex(3)).toBe 5 - expect(index.spanForIndex(4)).toBe 6 - expect(index.spanForIndex(5)).toBe 8 + expect(index.spanForIndex(0)).toBe 3 + expect(index.spanForIndex(1)).toBe 4 + expect(index.spanForIndex(2)).toBe 5 + expect(index.spanForIndex(3)).toBe 6 + expect(index.spanForIndex(4)).toBe 8 describe ".sliceBySpan(start, end)", -> describe "when the index contains values that start and end evenly on the given start/end span indices", -> @@ -85,12 +85,13 @@ describe "SpanIndex", -> expect(index.indexForSpan(5)).toEqual(index: 3, offset: 0) describe ".spanForIndex(index)", -> - it "returns the aggregate of spans for elements preceding the given index", -> + it "returns the aggregate of spans for all elements up to and including the given index", -> index.insert(0, [3, 0, 2, 0, 3, 1], ['a', 'b', 'c', 'd', 'e', 'f']) - expect(index.spanForIndex(0)).toBe 0 + expect(index.spanForIndex(0)).toBe 3 expect(index.spanForIndex(1)).toBe 3 - expect(index.spanForIndex(2)).toBe 3 + expect(index.spanForIndex(2)).toBe 5 expect(index.spanForIndex(3)).toBe 5 + expect(index.spanForIndex(4)).toBe 8 diff --git a/src/atom/line-wrapper.coffee b/src/atom/line-wrapper.coffee index 63fcb24d0..176d42fee 100644 --- a/src/atom/line-wrapper.coffee +++ b/src/atom/line-wrapper.coffee @@ -91,10 +91,10 @@ class LineWrapper screenPositionFromBufferPosition: (bufferPosition, allowEOL=false) -> bufferPosition = Point.fromObject(bufferPosition) - row = @index.spanForIndex(bufferPosition.row) + screenLines = @index.at(bufferPosition.row).screenLines + row = @index.spanForIndex(bufferPosition.row) - screenLines.length column = bufferPosition.column - screenLines = @index.at(bufferPosition.row).screenLines for screenLine, index in screenLines break if index == screenLines.length - 1 if allowEOL diff --git a/src/atom/span-index.coffee b/src/atom/span-index.coffee index c16c6ab10..44b56f529 100644 --- a/src/atom/span-index.coffee +++ b/src/atom/span-index.coffee @@ -66,7 +66,7 @@ class SpanIndex spanForIndex: (index) -> span = 0 - for i in [0...index] + for i in [0..index] span += @entries[i].span span