From e49ac783f8752c8c5dac2b2754374c2b1c7e5349 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 24 Jan 2017 12:18:09 +0100 Subject: [PATCH] Fix infinite recursion when calling getLastSelection from onDidAddCursor --- spec/text-editor-spec.coffee | 9 +++++++++ src/text-editor.coffee | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 9bb939c99..911270d16 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -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() diff --git a/src/text-editor.coffee b/src/text-editor.coffee index a825cb73b..2ebd106e6 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -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