if no address if specified for the first command, the address range become the entire file

This commit is contained in:
Corey Johnson
2012-10-29 17:52:45 -07:00
parent 66518a3c67
commit 7d6539068b
3 changed files with 33 additions and 0 deletions

View File

@@ -273,6 +273,25 @@ describe "CommandInterpreter", ->
runs ->
expect(buffer.lineForRow(6)).toBe ' current < pivot ? left.push(current) : right.push(current);'
describe "when there is no address range is given", ->
describe "when there is no text selection", ->
it "uses the entire file as the address range", ->
waitsForPromise ->
editSession.clearSelections()
interpreter.eval('s/current/foo/g', editSession)
runs ->
expect(buffer.lineForRow(3)).toBe ' var pivot = items.shift(), foo, left = [], right = [];'
expect(buffer.lineForRow(6)).toBe ' foo < pivot ? left.push(foo) : right.push(foo);'
describe "when text is selected", ->
it "uses the selection as the address range", ->
waitsForPromise ->
editSession.setSelectedBufferRange([[6, 0], [6, 44]])
interpreter.eval('s/current/foo/g', editSession)
runs ->
expect(buffer.lineForRow(3)).toBe ' var pivot = items.shift(), current, left = [], right = [];'
expect(buffer.lineForRow(6)).toBe ' foo < pivot ? left.push(foo) : right.push(current);'
describe "when not global", ->
describe "when there is a single selection", ->
it "performs a single substitution within the current selection", ->

View File

@@ -0,0 +1,9 @@
Address = require 'command-panel/src/commands/address'
Range = require 'range'
module.exports =
class AllLinesAddress extends Address
getRange: (buffer)->
buffer.getRange()
isRelative: -> false

View File

@@ -1,5 +1,6 @@
_ = require 'underscore'
$ = require 'jquery'
AllLinesAddress = require 'command-panel/src/commands/all-lines-address'
module.exports =
class CompositeCommand
@@ -7,6 +8,10 @@ class CompositeCommand
execute: (project, editSession) ->
currentRanges = editSession?.getSelectedBufferRanges()
if not @subcommands[0].isAddress() and currentRanges?.every((range) -> range.isEmpty())
@subcommands.unshift(new AllLinesAddress())
@executeCommands(@subcommands, project, editSession, currentRanges)
executeCommands: (commands, project, editSession, ranges) ->