Buffer.scanInRange can do a case-insensitive search

This commit is contained in:
Corey Johnson 2012-09-25 16:30:44 -07:00
parent 00f7796e93
commit 533ad84d03
2 changed files with 10 additions and 1 deletions

View File

@ -418,6 +418,13 @@ describe 'Buffer', ->
expect(buffer.getTextInRange(range)).toBe "ems.length <= 1) return items;\n var pivot = items.shift(), current, left = [], right = [];\n while("
describe ".scanInRange(range, regex, fn)", ->
describe "when given a regex with a ignore case flag", ->
it "does a case-insensitive search", ->
matches = []
buffer.scanInRange /cuRRent/i, [[0,0], [12,0]], (match, range) ->
matches.push(match)
expect(matches.length).toBe 1
describe "when given a regex with no global flag", ->
it "calls the iterator with the first match for the given regex in the given range", ->
matches = []

View File

@ -297,7 +297,9 @@ class Buffer
scanInRange: (regex, range, iterator, reverse=false) ->
range = Range.fromObject(range)
global = regex.global
regex = new RegExp(regex.source, 'gm')
flags = "gm"
flags += "i" if regex.ignoreCase
regex = new RegExp(regex.source, flags)
startIndex = @characterIndexForPosition(range.start)
endIndex = @characterIndexForPosition(range.end)