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

View File

@@ -282,6 +282,25 @@
textTags: ['p','span','div','br','b','strong','i','em','u','a','ul','ol','li'] 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;         window.__gjs = ed;