Ensure that all opened editors' buffers are added to the project

Assigning a language mode happens when adding a buffer to the project,
so we need to guarantee this happens to all buffers used by visible editors.
This commit is contained in:
Max Brunsfeld
2017-12-01 09:58:19 -08:00
parent 49d8d94218
commit 6e2ac3548f
2 changed files with 16 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
const path = require('path')
const temp = require('temp').track()
const dedent = require('dedent')
const TextBuffer = require('text-buffer')
const TextEditor = require('../src/text-editor')
const Workspace = require('../src/workspace')
const Project = require('../src/project')
@@ -933,6 +934,18 @@ describe('Workspace', () => {
})
})
})
describe('when opening an editor with a buffer that isn\'t part of the project', () => {
it('adds the buffer to the project', async () => {
const buffer = new TextBuffer()
const editor = new TextEditor({buffer})
await atom.workspace.open(editor)
expect(atom.project.getBuffers().map(buffer => buffer.id)).toContain(buffer.id)
expect(buffer.getLanguageMode().getLanguageId()).toBe('text.plain.null-grammar')
})
})
})
describe('finding items in the workspace', () => {

View File

@@ -497,6 +497,9 @@ module.exports = class Workspace extends Model {
this.textEditorRegistry.maintainConfig(item),
item.observeGrammar(this.handleGrammarUsed.bind(this))
)
if (!this.project.findBufferForId(item.buffer.id)) {
this.project.addBuffer(item.buffer)
}
item.onDidDestroy(() => { subscriptions.dispose() })
this.emitter.emit('did-add-text-editor', {textEditor: item, pane, index})
}