Substitution commands don't change editor selection

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-07-12 17:59:45 -06:00
parent bee6bf0ff5
commit 8e3c3a13a9
4 changed files with 10 additions and 11 deletions

View File

@@ -3,4 +3,4 @@ _ = require 'underscore'
module.exports =
class Command
isAddress: -> false
restoreSelections: false
preserveSelections: false

View File

@@ -5,19 +5,18 @@ class CompositeCommand
constructor: (@subcommands) ->
execute: (editor) ->
initialRanges = editor.getSelectedBufferRanges()
currentRanges = editor.getSelectedBufferRanges()
for command in @subcommands
newRanges = []
currentRanges = editor.getSelectedBufferRanges()
for currentRange in currentRanges
newRanges.push(command.execute(editor, currentRange)...)
for range in currentRanges
newRanges.push(command.execute(editor, range)...)
currentRanges = newRanges
for range in newRanges
unless command.preserveSelections
for range in currentRanges
for row in [range.start.row..range.end.row]
editor.destroyFoldsContainingBufferRow(row)
editor.setSelectedBufferRanges(newRanges)
editor.setSelectedBufferRanges(initialRanges) if command.restoreSelections
editor.setSelectedBufferRanges(currentRanges)
reverse: ->
new CompositeCommand(@subcommands.map (command) -> command.reverse())

View File

@@ -4,7 +4,7 @@ module.exports =
class Substitution extends Command
regex: null
replacementText: null
restoreSelections: true
preserveSelections: true
constructor: (pattern, replacementText, options) ->
@replacementText = replacementText