diff --git a/spec/atom/span-index-spec.coffee b/spec/atom/span-index-spec.coffee index ba2d1b5aa..d9ed2b9a1 100644 --- a/spec/atom/span-index-spec.coffee +++ b/spec/atom/span-index-spec.coffee @@ -5,6 +5,16 @@ describe "SpanIndex", -> beforeEach -> index = new SpanIndex + describe ".updateSpans(start, end, spans)", -> + 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 + describe ".sliceBySpan(start, end)", -> describe "when the index contains values that start and end evenly on the given start/end span indices", -> it "returns the spanning values with a start and end offset of 0", -> diff --git a/src/atom/span-index.coffee b/src/atom/span-index.coffee index 2bf917e44..f35f3a255 100644 --- a/src/atom/span-index.coffee +++ b/src/atom/span-index.coffee @@ -8,9 +8,16 @@ class SpanIndex insert: (index, spans, values) -> @entries[index..index] = @buildIndexEntries(spans, values) + replace: (index, span, value) -> + @splice(index, index, span, [value]) + splice: (start, end, spans, values) -> @entries[start..end] = @buildIndexEntries(spans, values) + updateSpans: (start, end, span) -> + for i in [start..end] + @entries[i].span = span + at: (index) -> @entries[index].value