Pass all ranges to each command when composing commands

This commit is contained in:
Nathan Sobo
2012-07-17 11:17:46 -06:00
parent 1d21de1e83
commit 4584f47cf2
4 changed files with 17 additions and 16 deletions

View File

@@ -3,7 +3,8 @@ Operation = require 'command-panel/operation'
module.exports =
class Address extends Command
compile: (project, buffer, range) ->
[new Operation(buffer: buffer, bufferRange: @getRange(buffer, range))]
compile: (project, buffer, ranges) ->
ranges.map (range) =>
new Operation(buffer: buffer, bufferRange: @getRange(buffer, range))
isAddress: -> true

View File

@@ -8,9 +8,7 @@ class CompositeCommand
currentRanges = editSession.getSelectedBufferRanges()
for command in @subcommands
operations?.forEach (o) -> o.destroy()
operations = []
for range in currentRanges
operations.push(command.compile(project, editSession.buffer, range)...)
operations = command.compile(project, editSession.buffer, currentRanges)
currentRanges = operations.map (o) -> o.getBufferRange()
editSession.clearAllSelections() unless command.preserveSelections

View File

@@ -8,8 +8,9 @@ class SelectAllMatches extends Command
constructor: (pattern) ->
@regex = new RegExp(pattern, 'g')
compile: (project, buffer, range) ->
compile: (project, buffer, ranges) ->
operations = []
buffer.scanInRange @regex, range, (match, matchRange) ->
operations.push(new Operation(buffer: buffer, bufferRange: matchRange))
for range in ranges
buffer.scanInRange @regex, range, (match, matchRange) ->
operations.push(new Operation(buffer: buffer, bufferRange: matchRange))
operations

View File

@@ -11,13 +11,14 @@ class Substitution extends Command
@replacementText = replacementText
@regex = new RegExp(pattern, options.join(''))
compile: (project, buffer, range) ->
compile: (project, buffer, ranges) ->
operations = []
buffer.scanInRange @regex, range, (match, matchRange, { replace }) =>
operations.push(new Operation(
buffer: buffer,
bufferRange: matchRange,
newText: @replacementText
preserveSelection: true
))
for range in ranges
buffer.scanInRange @regex, range, (match, matchRange, { replace }) =>
operations.push(new Operation(
buffer: buffer,
bufferRange: matchRange,
newText: @replacementText
preserveSelection: true
))
operations