diff --git a/spec/text-editor-registry-spec.js b/spec/text-editor-registry-spec.js index 388efb64a..14c7d805b 100644 --- a/spec/text-editor-registry-spec.js +++ b/spec/text-editor-registry-spec.js @@ -38,6 +38,7 @@ describe('TextEditorRegistry', function () { disposable.dispose() expect(registry.editors.size).toBe(0) expect(editor.registered).toBe(false) + expect(retainedEditorCount(registry)).toBe(0) }) }) @@ -103,6 +104,7 @@ describe('TextEditorRegistry', function () { editor.getBuffer().setPath('test.js') expect(editor.getGrammar().name).toBe('Null Grammar') + expect(retainedEditorCount(registry)).toBe(0) }) }) @@ -216,7 +218,7 @@ describe('TextEditorRegistry', function () { atom.config.set('core.fileEncoding', 'utf16be') expect(editor.getEncoding()).toBe('utf8') expect(getSubscriptionCount(editor)).toBe(previousSubscriptionCount) - expect(registry.editorsWithMaintainedConfig.size).toBe(0) + expect(retainedEditorCount(registry)).toBe(0) }) it('sets the encoding based on the config', function () { @@ -586,3 +588,11 @@ function getSubscriptionCount (editor) { editor.buffer.emitter.getTotalListenerCount() + editor.displayLayer.emitter.getTotalListenerCount() } + +function retainedEditorCount (registry) { + const editors = new Set() + registry.editors.forEach(e => editors.add(e)) + registry.editorsWithMaintainedConfig.forEach(e => editors.add(e)) + registry.editorsWithMaintainedGrammar.forEach(e => editors.add(e)) + return editors.size +} diff --git a/src/workspace.coffee b/src/workspace.coffee index 258e68fa3..7f51a37d0 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -164,10 +164,13 @@ class Workspace extends Model subscribeToAddedItems: -> @onDidAddPaneItem ({item, pane, index}) => if item instanceof TextEditor - @textEditorRegistry.maintainConfig(item) - @textEditorRegistry.maintainGrammar(item) - grammarSubscription = item.observeGrammar(@handleGrammarUsed.bind(this)) - item.onDidDestroy -> grammarSubscription.dispose() + subscriptions = new CompositeDisposable( + @textEditorRegistry.add(item) + @textEditorRegistry.maintainConfig(item) + @textEditorRegistry.maintainGrammar(item) + item.observeGrammar(@handleGrammarUsed.bind(this)) + ) + item.onDidDestroy -> subscriptions.dispose() @emitter.emit 'did-add-text-editor', {textEditor: item, pane, index} # Updates the application's title and proxy icon based on whichever file is