mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Pass all ranges to each command when composing commands
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user