mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
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.
29 lines
795 B
CoffeeScript
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()
|