"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:
Nathan Sobo
2012-07-17 16:32:20 -06:00
parent 4b147c04e5
commit d8189a6fc4
3 changed files with 17 additions and 11 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -4,6 +4,9 @@ class Operation
@buffer.retain()
@anchorRange = @buffer.addAnchorRange(bufferRange)
getPath: ->
@buffer.getPath()
getBufferRange: ->
@anchorRange.getBufferRange()