This commit is contained in:
2025-12-09 02:37:53 +01:00
parent 05b51947ee
commit fbd458f02d

View File

@@ -157,6 +157,30 @@
}
};
const insertPlaceholderIntoSelection = (rteInstance, html) => {
const doc = rteInstance && rteInstance.doc
? rteInstance.doc
: (rteInstance && rteInstance.el && rteInstance.el.ownerDocument) || document;
if (!doc) return false;
const sel = doc.getSelection && doc.getSelection();
if (!sel || !sel.rangeCount) return false;
const range = sel.getRangeAt(0);
if (!range) return false;
range.deleteContents();
const temp = doc.createElement('div');
temp.innerHTML = html;
const fragment = doc.createDocumentFragment();
while (temp.firstChild) {
fragment.appendChild(temp.firstChild);
}
range.insertNode(fragment);
range.collapse(false);
sel.removeAllRanges();
sel.addRange(range);
return true;
};
const openPlaceholderModal = (editor, component, opts = {}) => {
if (!editor) return;
const modal = editor.Modal;
@@ -431,10 +455,15 @@
openPlaceholderModal(editor, null, {
onSubmit: (payload) => {
const html = buildPlaceholderHTML(payload);
if (rteInstance && typeof rteInstance.insertHTML === 'function') {
let inserted = false;
if (insertPlaceholderIntoSelection(rteInstance, html)) {
inserted = true;
} else if (rteInstance && typeof rteInstance.insertHTML === 'function') {
rteInstance.insertHTML(html);
inserted = true;
} else if (typeof document !== 'undefined' && document.execCommand) {
document.execCommand('insertHTML', false, html);
inserted = true;
} else {
log('PLACEHOLDER ERROR', 'Placeholder konnte nicht eingefügt werden (kein RTE).', 'red', 'error');
return false;