mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
if no address if specified for the first command, the address range become the entire file
This commit is contained in:
@@ -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", ->
|
||||
|
||||
@@ -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
|
||||
@@ -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) ->
|
||||
|
||||
Reference in New Issue
Block a user