Substitution commands can replace text with empty string

Closes #488
This commit is contained in:
probablycorey
2013-05-06 12:11:15 -07:00
parent cc98b88e28
commit 43a3c93d9b
3 changed files with 8 additions and 2 deletions

View File

@@ -40,7 +40,7 @@ class CompositeCommand
if bufferRanges.length and not currentCommand.preserveSelections
editSession.setSelectedBufferRanges(bufferRanges, autoscroll: true)
operationsWillChangeBuffer = _.detect(operations, (operation) -> operation.newText)
operationsWillChangeBuffer = _.detect(operations, (operation) -> operation.newText?)
if operationsWillChangeBuffer
editSession.transact(executeOperations)

View File

@@ -19,7 +19,7 @@ class Operation
@getMarker().getRange()
execute: (editSession) ->
@getBuffer().change(@getBufferRange(), @newText) if @newText
@getBuffer().change(@getBufferRange(), @newText) if @newText?
@getBufferRange() unless @preserveSelection
preview: ->

View File

@@ -426,6 +426,12 @@ describe "CommandInterpreter", ->
runs ->
expect(buffer.lineForRow(6)).toBe '\t\t\tcurrent < pivot ? left.push(current) : right.push(current);'
it "removes matched text when an empty string is given as the replacement", ->
waitsForPromise ->
interpreter.eval('s/items//', editSession)
runs ->
expect(buffer.lineForRow(1)).toBe(' var sort = function() {')
describe "X x/regex/", ->
it "returns selection operations for all regex matches in all the project's files", ->
editSession.destroy()