Files
atom/src/packages/command-panel/lib/commands/substitution.coffee
Nathan Sobo 59a5a5bc8f Always pass a hash to TextBuffer.scanInRange iterators
This makes it easy to only assign variables for the information you
need in the iterator. Before, we always forced you to take a match and
a range as the first two arguments even if you weren't using them.
2013-04-03 11:16:49 -06:00

29 lines
795 B
CoffeeScript

Command = require './command'
Operation = require 'command-panel/lib/operation'
$ = require 'jquery'
module.exports =
class Substitution extends Command
regex: null
replacementText: null
preserveSelections: true
constructor: (pattern, replacementText, options) ->
@replacementText = replacementText
@regex = new RegExp(pattern, options.join(''))
compile: (project, buffer, ranges) ->
deferred = $.Deferred()
operations = []
for scanRange in ranges
buffer.scanInRange @regex, scanRange, ({range}) =>
operations.push(new Operation(
project: project
buffer: buffer
bufferRange: range
newText: @replacementText
preserveSelection: true
))
deferred.resolve(operations)
deferred.promise()