mirror of
https://github.com/moodle/moodle.git
synced 2025-03-20 07:30:01 +01:00
MDL-75078 editor_tiny: Fix undestroyed editors
Part of MDL-75966
This commit is contained in:
parent
417dee3a65
commit
41952a03b6
2
lib/editor/tiny/amd/build/editor.min.js
vendored
2
lib/editor/tiny/amd/build/editor.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -268,6 +268,26 @@ export const setupForTarget = async(target, options = {}) => {
|
||||
]);
|
||||
const {pluginNames, pluginConfig} = pluginValues;
|
||||
|
||||
// TinyMCE uses the element ID as a map key internally, even if the target has changed.
|
||||
// In the case where we have an editor in a modal form which has been detached from the DOM, but the editor not removed,
|
||||
// we need to manually destroy the editor.
|
||||
// We could theoretically do this with a Mutation Observer, but in some cases the Node may be moved,
|
||||
// or added back elsewhere in the DOM.
|
||||
const existingEditor = tinyMCE.EditorManager.get(target.id);
|
||||
if (existingEditor) {
|
||||
if (existingEditor.targetElm.closest('body')) {
|
||||
if (existingEditor.targetElm === target) {
|
||||
pendingPromise.resolve();
|
||||
return Promise.resolve(existingEditor);
|
||||
} else {
|
||||
pendingPromise.resolve();
|
||||
throw new Error('TinyMCE instance already exists for different target with same ID');
|
||||
}
|
||||
} else {
|
||||
existingEditor.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
// Allow plugins to modify the configuration.
|
||||
const instanceConfig = getStandardConfig(target, tinyMCE, options, pluginNames);
|
||||
pluginConfig.forEach((pluginConfig) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user