Clip range specified to Buffer.getTextInRange()

This commit is contained in:
Kevin Sawicki 2013-01-29 15:34:41 -08:00
parent 367927faa1
commit 1a04fa31d1
2 changed files with 13 additions and 1 deletions

View File

@ -465,6 +465,14 @@ describe 'Buffer', ->
range = [[2,10], [4,10]]
expect(buffer.getTextInRange(range)).toBe "ems.length <= 1) return items;\n var pivot = items.shift(), current, left = [], right = [];\n while("
describe "when the range starts before the start of the buffer", ->
it "clips the range to the start of the buffer", ->
expect(buffer.getTextInRange([[-Infinity, -Infinity], [0, Infinity]])).toBe buffer.lineForRow(0)
describe "when the range ends after the end of the buffer", ->
it "clips the range to the end of the buffer", ->
expect(buffer.getTextInRange([[12], [13, Infinity]])).toBe buffer.lineForRow(12)
describe ".scanInRange(range, regex, fn)", ->
describe "when given a regex with a ignore case flag", ->
it "does a case-insensitive search", ->

View File

@ -115,7 +115,7 @@ class Buffer
new Range([0, 0], [@getLastRow(), @getLastLine().length])
getTextInRange: (range) ->
range = Range.fromObject(range)
range = @clipRange(Range.fromObject(range))
if range.start.row == range.end.row
return @lineForRow(range.start.row)[range.start.column...range.end.column]
@ -220,6 +220,10 @@ class Buffer
new Point(row, column)
clipRange: (range) ->
range = Range.fromObject(range)
new Range(@clipPosition(range.start), @clipPosition(range.end))
prefixAndSuffixForRange: (range) ->
prefix: @lines[range.start.row][0...range.start.column]
suffix: @lines[range.end.row][range.end.column..]