Autoscroll to selections in model layer when added

Fixes #2698
This commit is contained in:
Nathan Sobo
2014-06-20 16:53:23 -06:00
parent 6cdb1a188a
commit e084bebb54
2 changed files with 18 additions and 1 deletions

View File

@@ -1220,6 +1220,21 @@ describe "Editor", ->
expect(editor.selectMarker(marker)).toBeFalsy()
expect(editor.getSelectedBufferRange()).toEqual [[0, 0], [0, 0]]
describe ".addSelectionForBufferRange(bufferRange)", ->
it "adds a selection for the specified buffer range", ->
editor.addSelectionForBufferRange([[3, 4], [5, 6]])
expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [0, 0]], [[3, 4], [5, 6]]]
it "autoscrolls to the added selection if needed", ->
editor.setLineHeightInPixels(10)
editor.setDefaultCharWidth(10)
editor.setHeight(50)
editor.setWidth(50)
editor.addSelectionForBufferRange([[8, 10], [8, 15]])
expect(editor.getScrollTop()).toBe 75
expect(editor.getScrollLeft()).toBe 160
describe ".addSelectionBelow()", ->
describe "when the selection is non-empty", ->
it "selects the same region of the line below current selections if possible", ->

View File

@@ -1278,7 +1278,9 @@ class Editor extends Model
# Returns the added {Selection}.
addSelectionForBufferRange: (bufferRange, options={}) ->
@markBufferRange(bufferRange, _.defaults(@getSelectionMarkerAttributes(), options))
@getLastSelection()
selection = @getLastSelection()
selection.autoscroll()
selection
# Public: Set the selected range in buffer coordinates. If there are multiple
# selections, they are reduced to a single selection with the given range.