This commit is contained in:
2026-01-11 03:26:47 +01:00
parent da539b6ce1
commit 5bf06f75d6
2 changed files with 46 additions and 26 deletions

View File

@@ -619,24 +619,19 @@ const buildPlaceholderHTML = (payload) => {
log('PLACEHOLDER ERROR', 'Keine Text-Selektion gefunden. Bitte Cursor setzen und erneut versuchen.', 'red', 'error');
return;
}
let markerId = null;
const markerId = `bridge-placeholder-marker-${Date.now()}-${Math.random().toString(36).slice(2)}`;
const restoreSelection = () => restoreRteSelection(selectionSnapshot);
const ensureMarker = () => {
if (markerId) return true;
if (!restoreSelection()) return false;
markerId = `bridge-placeholder-marker-${Date.now()}-${Math.random().toString(36).slice(2)}`;
const inserted = insertPlaceholderIntoSelection(rteInstance, `<span ${PLACEHOLDER_MARKER_ATTR}="${markerId}"></span>`);
if (inserted) {
let markerInserted = false;
if (restoreSelection()) {
markerInserted = insertCaretMarker(rteInstance, markerId);
if (markerInserted) {
setTimeout(() => reparseTextComponent(target, editor), 0);
return true;
}
markerId = null;
return false;
};
}
const cleanupMarker = () => {
if (markerId) {
if (markerInserted) {
removeMarkerFromComponent(target, markerId, editor);
markerId = null;
markerInserted = false;
}
};
openPlaceholderModal(editor, null, {
@@ -647,25 +642,27 @@ const buildPlaceholderHTML = (payload) => {
}
},
onSubmit: (payload) => {
if (!ensureMarker()) {
cleanupMarker();
if (restoreSelection()) {
if (editor) {
editor.__bridgePlaceholderSuppressAdd = (editor.__bridgePlaceholderSuppressAdd || 0) + 1;
}
let replaced = false;
if (markerInserted) {
replaced = replaceMarkerWithPlaceholder(target, markerId, payload, editor);
}
if (!replaced && restoreSelection()) {
const html = buildPlaceholderHTML(payload);
if (insertPlaceholderIntoSelection(rteInstance, html)) {
setTimeout(() => reparseTextComponent(target, editor), 0);
return true;
replaced = true;
}
}
log('PLACEHOLDER ERROR', 'Placeholder konnte nicht eingefügt werden (Marker fehlte).', 'red', 'error');
return false;
}
const replaced = replaceMarkerWithPlaceholder(target, markerId, payload, editor);
if (!replaced) {
cleanupMarker();
const viewEl = target.view && target.view.el;
if (viewEl) {
viewEl.insertAdjacentHTML('beforeend', buildPlaceholderHTML(payload));
reparseTextComponent(target, editor);
replaced = true;
} else {
log('PLACEHOLDER ERROR', 'Placeholder konnte nicht eingefügt werden (kein Ziel).', 'red', 'error');
return false;
@@ -674,7 +671,7 @@ const buildPlaceholderHTML = (payload) => {
if (rteInstance && typeof rteInstance.focus === 'function') {
setTimeout(() => rteInstance.focus(), 0);
}
return true;
return replaced;
}
});
},
@@ -1062,6 +1059,10 @@ const buildPlaceholderHTML = (payload) => {
editor.on('component:add', (cmp) => {
if (!cmp || !cmp.is || !cmp.is(PLACEHOLDER_COMPONENT)) return;
if (editor.__bridgePlaceholderSuppressAdd) {
editor.__bridgePlaceholderSuppressAdd = Math.max(0, (editor.__bridgePlaceholderSuppressAdd || 1) - 1);
return;
}
if (window.__GJS_IS_PARSING) return;
if (cmp.__bridgePlaceholderPrompted) return;
cmp.__bridgePlaceholderPrompted = true;

View File

@@ -282,6 +282,25 @@
textTags: ['p','span','div','br','b','strong','i','em','u','a','ul','ol','li']
}
});
try {
const textTags = ['p','span','div','br','b','strong','i','em','u','a','ul','ol','li'];
if (ed.Config) {
ed.Config.domComponents = ed.Config.domComponents || {};
ed.Config.domComponents.textTags = textTags;
}
if (ed.DomComponents && ed.DomComponents.getConfig) {
ed.DomComponents.getConfig().textTags = textTags;
}
if (ed.Parser && ed.Parser.getConfig) {
const parserCfg = ed.Parser.getConfig();
parserCfg.textTags = textTags;
parserCfg.optionsHtml = parserCfg.optionsHtml || {};
parserCfg.optionsHtml.textTags = textTags;
}
} catch (e) {
log('CORE WARN', `textTags Konfiguration fehlgeschlagen: ${e.message}`, 'orange', 'warn');
}
        
        window.__gjs = ed;