mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Clip range specified to Buffer.getTextInRange()
This commit is contained in:
parent
367927faa1
commit
1a04fa31d1
@ -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", ->
|
||||
|
@ -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..]
|
||||
|
Loading…
Reference in New Issue
Block a user