mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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', () => {
|
||||
|
||||
@@ -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})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user