mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-06 23:26:25 +03:00
Add lineText and lineTextOffset to buffer.scan
This commit is contained in:
parent
9c4d239696
commit
00cdb3e317
@ -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", ->
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user