Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading of userData into tinymce control after initialisation #1537

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/js/control/textarea.tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ export default class controlTinymce extends controlTextarea {
const afterInit = function (inst) {
// Set userData
if (copiedData) {
inst.setContent(copiedData)
inst[0].setContent(copiedData)
} else if (userData) {
inst.setContent(userData)
inst[0].setContent(userData)
}
}

setTimeout(() => {
// initialise the editor
// initialise the editor within a timeout so that the main thread can continue while tinymce initialises
window.tinymce.init(options).then(afterInit)
}, 0)
}
Expand Down
23 changes: 16 additions & 7 deletions tests/control/textarea.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import controlTinymce from '../../src/js/control/textarea.tinymce'
import controlQuill from '../../src/js/control/textarea.quill'
import { getScripts, getStyles, isCached } from '../../src/js/utils'

const sleep = milliseconds => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}

const loadResources = async (js, css) => {
if (css) {
getStyles(css)
Expand Down Expand Up @@ -59,6 +55,7 @@ describe('Test building text variations and subtypes', () => {
'name': 'tinymce-elem',
'access': false,
'subtype': 'tinymce',
userData: ['AValue'],
}, false)
controlInstance.configure()
const element = controlInstance.build()
Expand All @@ -71,9 +68,21 @@ describe('Test building text variations and subtypes', () => {

expect(window.tinymce).not.toBeUndefined()
controlInstance.onRender()
await sleep(2000)
expect(window.tinymce.get('tinymce-elem')).not.toBeNull()
})
//Await tinymce initialisation, this can take many seconds
await (new Promise(resolve => {
const timer = setInterval(() => {
const tinyInstance = window.tinymce.get('tinymce-elem')
if (tinyInstance !== null && tinyInstance.initialized) {
clearTimeout(timer)
resolve()
}
}, 500)
}))
const tinyInstance = window.tinymce.get('tinymce-elem')
expect(tinyInstance).not.toBeNull()
expect(tinyInstance.initialized).toBeTruthy()
expect(tinyInstance.getContent()).toBe('<p>AValue</p>')
},20000) //Longer timeout for tinymce initialisation

test('can render Quill', async () => {
const controlInstance = new controlQuill({
Expand Down
Loading