diff --git a/spec/text-editor-element-spec.js b/spec/text-editor-element-spec.js index c92c6f144..684d160a8 100644 --- a/spec/text-editor-element-spec.js +++ b/spec/text-editor-element-spec.js @@ -9,6 +9,10 @@ describe('TextEditorElement', () => { beforeEach(() => { jasmineContent = document.body.querySelector('#jasmine-content') + // Force scrollbars to be visible regardless of local system configuration + const scrollbarStyle = document.createElement('style') + scrollbarStyle.textContent = '::-webkit-scrollbar { -webkit-appearance: none }' + jasmine.attachToDOM(scrollbarStyle) }) function buildTextEditorElement (options = {}) { @@ -201,6 +205,33 @@ describe('TextEditorElement', () => { }) }) + describe('::setModel', () => { + describe('when the element does not have an editor yet', () => { + it('uses the supplied one', () => { + const element = buildTextEditorElement({attach: false}) + const editor = new TextEditor() + element.setModel(editor) + jasmine.attachToDOM(element) + expect(editor.element).toBe(element) + expect(element.getModel()).toBe(editor) + }) + }) + + describe('when the element already has an editor', () => { + it('unbinds it and then swaps it with the supplied one', async () => { + const element = buildTextEditorElement({attach: true}) + const previousEditor = element.getModel() + expect(previousEditor.element).toBe(element) + + const newEditor = new TextEditor() + element.setModel(newEditor) + expect(previousEditor.element).not.toBe(element) + expect(newEditor.element).toBe(element) + expect(element.getModel()).toBe(newEditor) + }) + }) + }) + describe('::onDidAttach and ::onDidDetach', () => it('invokes callbacks when the element is attached and detached', () => { const element = buildTextEditorElement({attach: false}) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 037e45462..a93cbabba 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -174,6 +174,10 @@ class TextEditorComponent { } update (props) { + if (props.model !== this.props.model) { + this.props.model.component = null + props.model.component = this + } this.props = props this.scheduleUpdate() }