mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Commands terminating in a substitution restore their initial selection
This commit is contained in:
@@ -239,6 +239,12 @@ describe "CommandInterpreter", ->
|
||||
expect(buffer.lineForRow(5)).toBe ' foo = items.shift();'
|
||||
expect(buffer.lineForRow(6)).toBe ' foo < pivot ? left.push(foo) : right.push(current);'
|
||||
|
||||
describe "when prefixed with an address", ->
|
||||
it "restores the original selections upon completion if it is the last command", ->
|
||||
editor.setSelectedBufferRanges([[[5, 0], [5, 20]], [[6, 0], [6, 44]]])
|
||||
interpreter.eval(editor, ',s/current/foo/g')
|
||||
expect(editor.getSelectedBufferRanges()).toEqual [[[5, 0], [5, 20]], [[6, 0], [6, 44]]]
|
||||
|
||||
describe "when command selects folded text", ->
|
||||
it "unfolds lines that command selects", ->
|
||||
editor.createFold(1, 9)
|
||||
|
||||
@@ -351,7 +351,7 @@ class EditSession
|
||||
@getLastSelection().getBufferRange()
|
||||
|
||||
getSelectedBufferRanges: ->
|
||||
selection.getBufferRange() for selection in @selections
|
||||
selection.getBufferRange() for selection in @getSelectionsOrderedByBufferPosition()
|
||||
|
||||
getSelectedText: ->
|
||||
@getLastSelection().getText()
|
||||
|
||||
@@ -184,6 +184,7 @@ class Editor extends View
|
||||
getSelectionsOrderedByBufferPosition: -> @activeEditSession.getSelectionsOrderedByBufferPosition()
|
||||
getLastSelectionInBuffer: -> @activeEditSession.getLastSelectionInBuffer()
|
||||
getSelectedText: -> @activeEditSession.getSelectedText()
|
||||
getSelectedBufferRanges: -> @activeEditSession.getSelectedBufferRanges()
|
||||
getSelectedBufferRange: -> @activeEditSession.getSelectedBufferRange()
|
||||
setSelectedBufferRange: (bufferRange, options) -> @activeEditSession.setSelectedBufferRange(bufferRange, options)
|
||||
setSelectedBufferRanges: (bufferRanges, options) -> @activeEditSession.setSelectedBufferRanges(bufferRanges, options)
|
||||
|
||||
@@ -3,3 +3,4 @@ _ = require 'underscore'
|
||||
module.exports =
|
||||
class Command
|
||||
isAddress: -> false
|
||||
restoreSelections: false
|
||||
|
||||
@@ -5,9 +5,10 @@ class CompositeCommand
|
||||
constructor: (@subcommands) ->
|
||||
|
||||
execute: (editor) ->
|
||||
initialRanges = editor.getSelectedBufferRanges()
|
||||
for command in @subcommands
|
||||
newRanges = []
|
||||
currentRanges = editor.getSelectionsOrderedByBufferPosition().map (selection) -> selection.getBufferRange()
|
||||
currentRanges = editor.getSelectedBufferRanges()
|
||||
for currentRange in currentRanges
|
||||
newRanges.push(command.execute(editor, currentRange)...)
|
||||
|
||||
@@ -16,6 +17,7 @@ class CompositeCommand
|
||||
editor.destroyFoldsContainingBufferRow(row)
|
||||
|
||||
editor.setSelectedBufferRanges(newRanges)
|
||||
editor.setSelectedBufferRanges(initialRanges) if command.restoreSelections
|
||||
|
||||
reverse: ->
|
||||
new CompositeCommand(@subcommands.map (command) -> command.reverse())
|
||||
|
||||
@@ -4,6 +4,7 @@ module.exports =
|
||||
class Substitution extends Command
|
||||
regex: null
|
||||
replacementText: null
|
||||
restoreSelections: true
|
||||
|
||||
constructor: (pattern, replacementText, options) ->
|
||||
@replacementText = replacementText
|
||||
|
||||
Reference in New Issue
Block a user