diff --git a/public/editor/bridge-core.js b/public/editor/bridge-core.js index 0f1153b..a0a15bd 100644 --- a/public/editor/bridge-core.js +++ b/public/editor/bridge-core.js @@ -340,11 +340,25 @@ return type === 'text' || type === 'link' || type === 'button'; }; + const modelHasContent = (cmp) => { + if (!cmp) return false; + if (typeof cmp.components === 'function') { + const comps = cmp.components(); + if (comps && comps.length) return true; + } + if (typeof cmp.get === 'function') { + const content = cmp.get('content'); + if (typeof content === 'string' && content !== '') return true; + } + return false; + }; + const fixPlainTextContent = (cmp) => { if (!cmp || !cmp.view || !cmp.view.el) return; if (!isTextLike(cmp)) return; const el = cmp.view.el; if (!hasPlainTextNodes(el)) return; + if (modelHasContent(cmp)) return; const comps = buildTextnodeComponents(el); if (!comps.length) return; try { @@ -361,23 +375,16 @@ ed.on('rte:disable', (cmp) => { if (ed.__bridgeFixPlainText) return; ed.__bridgeFixPlainText = true; - try { - fixPlainTextContent(cmp); - } finally { - ed.__bridgeFixPlainText = false; - } + setTimeout(() => { + try { + fixPlainTextContent(cmp); + } finally { + ed.__bridgeFixPlainText = false; + } + }, 0); }); - ed.on('component:update', (cmp) => { - if (ed.__bridgeFixPlainText) return; - if (!isTextLike(cmp)) return; - ed.__bridgeFixPlainText = true; - try { - fixPlainTextContent(cmp); - } finally { - ed.__bridgeFixPlainText = false; - } - }); + // Keep the fix off live updates to avoid cursor jumps; run only on RTE close.                  window.__gjs = ed;