mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Don't freak when selections are added & removed before display update
Previously, if a selection was added and removed before the editor got a chance to update its display, it would try to add a selection view for the destroyed selection. Now we check the new selections and cursors to make sure they aren't destroyed before we add views for them.
This commit is contained in:
@@ -765,6 +765,18 @@ describe "Editor", ->
|
||||
expect(editor.getSelectionViews().length).toBe 1
|
||||
expect(editor.find('.region').length).toBe 3
|
||||
|
||||
describe "when a selection is added and removed before the display is updated", ->
|
||||
it "does not attempt to render the selection", ->
|
||||
# don't update display until we request it
|
||||
jasmine.unspy(editor, 'requestDisplayUpdate')
|
||||
spyOn(editor, 'requestDisplayUpdate')
|
||||
|
||||
editSession = editor.activeEditSession
|
||||
selection = editSession.addSelectionForBufferRange([[3, 0], [3, 4]])
|
||||
selection.destroy()
|
||||
editor.updateDisplay()
|
||||
expect(editor.getSelectionViews().length).toBe 1
|
||||
|
||||
describe "when the selection is created with the selectAll event", ->
|
||||
it "does not scroll to the end of the buffer", ->
|
||||
editor.height(150)
|
||||
|
||||
@@ -34,6 +34,7 @@ class Cursor
|
||||
@needsAutoscroll = true
|
||||
|
||||
destroy: ->
|
||||
@destroyed = true
|
||||
@editSession.destroyMarker(@marker)
|
||||
@editSession.removeCursor(this)
|
||||
@trigger 'destroyed'
|
||||
|
||||
@@ -780,7 +780,7 @@ class Editor extends View
|
||||
|
||||
updateCursorViews: ->
|
||||
if @newCursors.length > 0
|
||||
@addCursorView(cursor) for cursor in @newCursors
|
||||
@addCursorView(cursor) for cursor in @newCursors when not cursor.destroyed
|
||||
@syncCursorAnimations()
|
||||
@newCursors = []
|
||||
|
||||
@@ -792,7 +792,7 @@ class Editor extends View
|
||||
|
||||
updateSelectionViews: ->
|
||||
if @newSelections.length > 0
|
||||
@addSelectionView(selection) for selection in @newSelections
|
||||
@addSelectionView(selection) for selection in @newSelections when not selection.destroyed
|
||||
@newSelections = []
|
||||
|
||||
for selectionView in @getSelectionViews()
|
||||
|
||||
Reference in New Issue
Block a user