Add selectToBufferPosition

This commit is contained in:
Ben Ogle
2014-09-02 14:09:56 -07:00
parent 5ea64f8b11
commit 659c05c825
2 changed files with 23 additions and 0 deletions

View File

@@ -925,6 +925,18 @@ describe "Editor", ->
expect(selection1.getScreenRange()).toEqual([[0, 9], [1, 21]])
expect(selection1.isReversed()).toBeFalsy()
describe ".selectToBufferPosition(bufferPosition)", ->
it "expands the last selection to the given position", ->
editor.setSelectedBufferRange([[3, 0], [4, 5]])
editor.addCursorAtBufferPosition([5, 6])
editor.selectToBufferPosition([6, 2])
selections = editor.getSelections()
expect(selections.length).toBe 2
[selection1, selection2] = selections
expect(selection1.getBufferRange()).toEqual [[3, 0], [4, 5]]
expect(selection2.getBufferRange()).toEqual [[5, 6], [6, 2]]
describe ".selectToScreenPosition(screenPosition)", ->
it "expands the last selection to the given position", ->
editor.setSelectedBufferRange([[3, 0], [4, 5]])

View File

@@ -1923,6 +1923,17 @@ class Editor extends Model
selection.autoscroll() if @manageScrollPosition
selection
# Essential: Select from the current cursor position to the given position in
# buffer coordinates.
#
# This method may merge selections that end up intesecting.
#
# * `position` An instance of {Point}, with a given `row` and `column`.
selectToBufferPosition: (position) ->
lastSelection = @getLastSelection()
lastSelection.selectToBufferPosition(position)
@mergeIntersectingSelections(reversed: lastSelection.isReversed())
# Essential: Select from the current cursor position to the given position in
# screen coordinates.
#