Autoscroll to cursor after clearing multi-cursor selection.

This commit is contained in:
Collin Donahue-Oponski
2015-12-11 15:32:29 -07:00
parent 4708d5ba88
commit e4e200317a
2 changed files with 28 additions and 6 deletions

View File

@@ -2119,20 +2119,42 @@ describe "TextEditor", ->
editor.splitSelectionsIntoLines()
expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [0, 3]]]
describe ".consolidateSelections()", ->
it "destroys all selections but the least recent, returning true if any selections were destroyed", ->
editor.setSelectedBufferRange([[3, 16], [3, 21]])
selection1 = editor.getLastSelection()
describe "::consolidateSelections()", ->
makeMultipleSelections = ->
selection.setBufferRange [[3, 16], [3, 21]]
selection2 = editor.addSelectionForBufferRange([[3, 25], [3, 34]])
selection3 = editor.addSelectionForBufferRange([[8, 4], [8, 10]])
selection4 = editor.addSelectionForBufferRange([[1, 6], [1, 10]])
expect(editor.getSelections()).toEqual [selection, selection2, selection3, selection4]
[selection, selection2, selection3, selection4]
it "destroys all selections but the least recent, returning true if any selections were destroyed", ->
[selection1] = makeMultipleSelections()
expect(editor.getSelections()).toEqual [selection1, selection2, selection3]
expect(editor.consolidateSelections()).toBeTruthy()
expect(editor.getSelections()).toEqual [selection1]
expect(selection1.isEmpty()).toBeFalsy()
expect(editor.consolidateSelections()).toBeFalsy()
expect(editor.getSelections()).toEqual [selection1]
it "scrolls to the remaining selection", ->
[selection1] = makeMultipleSelections()
atom.config.set('editor.scrollPastEnd', true)
editor.setHeight(100, true)
editor.setLineHeightInPixels(10)
editor.setFirstVisibleScreenRow(10)
expect(editor.getVisibleRowRange()[0]).toBeGreaterThan(selection1.getBufferRowRange()[1])
editor.consolidateSelections()
waitsForPromise ->
new Promise((resolve) -> window.requestAnimationFrame(resolve))
runs ->
expect(editor.getVisibleRowRange()[0]).not.toBeGreaterThan(selection1.getBufferRowRange()[0])
expect(editor.getVisibleRowRange()[1]).not.toBeLessThan(selection1.getBufferRowRange()[0])
describe "when the cursor is moved while there is a selection", ->
makeSelection = -> selection.setBufferRange [[1, 2], [1, 5]]

View File

@@ -2437,7 +2437,7 @@ class TextEditor extends Model
selections = @getSelections()
if selections.length > 1
selection.destroy() for selection in selections[1...(selections.length)]
selections[0].autoscroll()
selections[0].autoscroll(center: true)
true
else
false