mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
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:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user