mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
"X x/regex/" command returns operations
Also, passing an EditSession is optional when calling CommandInterpreter.eval. X commands don't require it, but other commands will throw exceptions if it's missing.
This commit is contained in:
@@ -13,7 +13,7 @@ describe "CommandInterpreter", ->
|
||||
buffer = editSession.buffer
|
||||
|
||||
afterEach ->
|
||||
editSession.destroy()
|
||||
editSession?.destroy()
|
||||
expect(buffer.getAnchors().length).toBe 0
|
||||
|
||||
describe "addresses", ->
|
||||
@@ -310,16 +310,19 @@ describe "CommandInterpreter", ->
|
||||
it "returns selection operations for all regex matches in all the project's files", ->
|
||||
editSession.destroy()
|
||||
project = new Project(fixturesProject.resolve('dir/'))
|
||||
interpreter = new CommandInterpreter(fixturesProject)
|
||||
editSession = project.open('a')
|
||||
interpreter = new CommandInterpreter(project)
|
||||
|
||||
operations = null
|
||||
waitsForPromise ->
|
||||
interpreter.eval("X x/a+/", editSession).done (ops) ->
|
||||
operations = ops
|
||||
interpreter.eval("X x/a+/").done (ops) -> operations = ops
|
||||
|
||||
runs ->
|
||||
console.log operations
|
||||
expect(operations.length).toBeGreaterThan 3
|
||||
for operation in operations
|
||||
editSession = project.open(operation.getPath())
|
||||
operation.execute(editSession)
|
||||
expect(editSession.getSelectedText()).toMatch /a+/
|
||||
editSession.destroy()
|
||||
operation.destroy()
|
||||
|
||||
|
||||
operation.destroy() for operation in operations
|
||||
editSession = null
|
||||
|
||||
@@ -6,14 +6,14 @@ class CompositeCommand
|
||||
constructor: (@subcommands) ->
|
||||
|
||||
execute: (project, editSession) ->
|
||||
currentRanges = editSession.getSelectedBufferRanges()
|
||||
currentRanges = editSession?.getSelectedBufferRanges()
|
||||
@executeCommands(@subcommands, project, editSession, currentRanges)
|
||||
|
||||
executeCommands: (commands, project, editSession, ranges) ->
|
||||
deferred = $.Deferred()
|
||||
[currentCommand, remainingCommands...] = commands
|
||||
|
||||
currentCommand.compile(project, editSession.buffer, ranges).done (operations) =>
|
||||
currentCommand.compile(project, editSession?.buffer, ranges).done (operations) =>
|
||||
if remainingCommands.length
|
||||
nextRanges = operations.map (operation) ->
|
||||
operation.destroy()
|
||||
@@ -21,7 +21,7 @@ class CompositeCommand
|
||||
@executeCommands(remainingCommands, project, editSession, nextRanges).done ->
|
||||
deferred.resolve()
|
||||
else
|
||||
editSession.clearAllSelections() unless currentCommand.preserveSelections
|
||||
editSession?.clearAllSelections() unless currentCommand.preserveSelections
|
||||
if currentCommand.previewOperations
|
||||
deferred.resolve(operations)
|
||||
else
|
||||
|
||||
@@ -4,6 +4,9 @@ class Operation
|
||||
@buffer.retain()
|
||||
@anchorRange = @buffer.addAnchorRange(bufferRange)
|
||||
|
||||
getPath: ->
|
||||
@buffer.getPath()
|
||||
|
||||
getBufferRange: ->
|
||||
@anchorRange.getBufferRange()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user