x/$/ places cursors at end of lines in current selection

Editor addSelectionForBufferRange no longer attempts to recycle an existing empty selection, because this was interfering with x selecting zero-width matches. It always adds a new selection, and tools must take care to use it correctly.
This commit is contained in:
Nathan Sobo
2012-03-29 11:46:56 -07:00
parent 9ba88959bb
commit fc76bed81e
3 changed files with 14 additions and 7 deletions

View File

@@ -123,6 +123,17 @@ describe "CommandInterpreter", ->
expect(selections[2].getBufferRange()).toEqual [[6,34], [6,41]]
expect(selections[3].getBufferRange()).toEqual [[6,56], [6,63]]
describe "when matching /$/", ->
it "matches the end of each line in the selected region", ->
interpreter.eval(editor, '6,8 x/$/')
cursors = editor.getCursors()
expect(cursors.length).toBe 3
expect(cursors[0].getBufferPosition()).toEqual [5, 30]
expect(cursors[1].getBufferPosition()).toEqual [6, 65]
expect(cursors[2].getBufferPosition()).toEqual [7, 5]
it "loops through current selections and selects text matching the regex", ->
editor.setSelectionBufferRange [[3,0], [3,62]]
editor.addSelectionForBufferRange [[6,0], [6,65]]

View File

@@ -15,4 +15,5 @@ class SelectAllMatches extends Command
rangesToSelect.push(range)
editor.clearSelections()
editor.addSelectionForBufferRange(range) for range in rangesToSelect
editor.setSelectionBufferRange(rangesToSelect[0])
editor.addSelectionForBufferRange(range) for range in rangesToSelect[1..]

View File

@@ -30,12 +30,7 @@ class CompositeSeleciton
@editor.lines.append(selection)
addSelectionForBufferRange: (bufferRange, options) ->
selections = @getSelections()
cursor = if selections.length == 1 and selections[0].isEmpty()
selections[0].cursor
else
@editor.compositeCursor.addCursor()
cursor = @editor.compositeCursor.addCursor()
@selectionForCursor(cursor).setBufferRange(bufferRange, options)
removeSelectionForCursor: (cursor) ->