From 659c05c8259bf943f01a2febbb3e671b62ccd5fe Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 2 Sep 2014 14:09:56 -0700 Subject: [PATCH] Add selectToBufferPosition --- spec/editor-spec.coffee | 12 ++++++++++++ src/editor.coffee | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 2ccc4ca40..3d6bdada8 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -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]]) diff --git a/src/editor.coffee b/src/editor.coffee index 3d47bcc8d..f71597fb6 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -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. #