mirror of
https://github.com/atom/atom.git
synced 2026-01-25 14:59:03 -05:00
🚱 Stop maintaining destroyed editors' grammar and config
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user