Merge pull request #13687 from atom/as-fix-stackoverflow-exception

Fix infinite recursion when calling `editor.getLastSelection` from an `onDidAddCursor` event handler
This commit is contained in:
Antonio Scandurra
2017-01-24 13:49:34 +01:00
committed by GitHub
2 changed files with 10 additions and 1 deletions

View File

@@ -1191,6 +1191,15 @@ describe "TextEditor", ->
editor.getLastSelection().destroy()
expect(editor.getLastSelection().getBufferRange()).toEqual([[0, 0], [0, 0]])
it "doesn't get stuck in a infinite loop when called from ::onDidAddCursor after the last selection has been destroyed (regression)", ->
callCount = 0
editor.getLastSelection().destroy()
editor.onDidAddCursor (cursor) ->
callCount++
editor.getLastSelection()
expect(editor.getLastSelection().getBufferRange()).toEqual([[0, 0], [0, 0]])
expect(callCount).toBe(1)
describe ".getSelections()", ->
it "creates a new selection at (0, 0) if the last selection has been destroyed", ->
editor.getLastSelection().destroy()

View File

@@ -2284,7 +2284,6 @@ class TextEditor extends Model
@decorateMarker(marker, type: 'line-number', class: 'cursor-line')
@decorateMarker(marker, type: 'line-number', class: 'cursor-line-no-selection', onlyHead: true, onlyEmpty: true)
@decorateMarker(marker, type: 'line', class: 'cursor-line', onlyEmpty: true)
@emitter.emit 'did-add-cursor', cursor
cursor
moveCursors: (fn) ->
@@ -2773,6 +2772,7 @@ class TextEditor extends Model
if selection.intersectsBufferRange(selectionBufferRange)
return selection
else
@emitter.emit 'did-add-cursor', cursor
@emitter.emit 'did-add-selection', selection
selection