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:
Nathan Sobo
2013-04-04 19:05:22 -06:00
parent 31579703f0
commit f6bfab5dd7
3 changed files with 15 additions and 2 deletions

View File

@@ -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)

View File

@@ -34,6 +34,7 @@ class Cursor
@needsAutoscroll = true
destroy: ->
@destroyed = true
@editSession.destroyMarker(@marker)
@editSession.removeCursor(this)
@trigger 'destroyed'

View File

@@ -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()