mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Merge pull request #15013 from atom/as-fix-calling-editor-element-set-model
Swap underlying editor correctly when calling setModel on editor element
This commit is contained in:
commit
9be492fcb3
@ -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})
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user