diff --git a/spec/text-buffer-spec.coffee b/spec/text-buffer-spec.coffee index bb715a467..ec6efb63f 100644 --- a/spec/text-buffer-spec.coffee +++ b/spec/text-buffer-spec.coffee @@ -602,6 +602,17 @@ describe 'TextBuffer', -> it "clips the range to the end of the buffer", -> expect(buffer.getTextInRange([[12], [13, Infinity]])).toBe buffer.lineForRow(12) + describe ".scan(regex, fn)", -> + it "retunrns lineText and lineTextOffset", -> + matches = [] + buffer.scan /current/, (match) -> + matches.push(match) + expect(matches.length).toBe 1 + + expect(matches[0].matchText).toEqual 'current' + expect(matches[0].lineText).toEqual ' var pivot = items.shift(), current, left = [], right = [];' + expect(matches[0].lineTextOffset).toBe 0 + describe ".scanInRange(range, regex, fn)", -> describe "when given a regex with a ignore case flag", -> it "does a case-insensitive search", -> diff --git a/src/text-buffer.coffee b/src/text-buffer.coffee index cfad306c0..0b1431061 100644 --- a/src/text-buffer.coffee +++ b/src/text-buffer.coffee @@ -6,6 +6,7 @@ File = require './file' EventEmitter = require './event-emitter' Subscriber = require './subscriber' guid = require 'guid' +{P} = require 'scandal' # Private: Represents the contents of a file. # @@ -501,7 +502,10 @@ class TextBuffer # regex - A {RegExp} representing the text to find # iterator - A {Function} that's called on each match scan: (regex, iterator) -> - @scanInRange(regex, @getRange(), iterator) + @scanInRange regex, @getRange(), (result) => + result.lineText = @lineForRow(result.range.start.row) + result.lineTextOffset = 0 + iterator(result) # Scans for text in a given range, calling a function on each match. # @@ -538,7 +542,8 @@ class TextBuffer range = new Range(startPosition, endPosition) keepLooping = true replacementText = null - iterator({match, range, stop, replace }) + matchText = match[0] + iterator({ match, matchText, range, stop, replace }) if replacementText? @change(range, replacementText)