This commit is contained in:
2026-01-15 03:20:49 +01:00
parent 27a79a58a2
commit 0143adbc96
2 changed files with 41 additions and 1 deletions

View File

@@ -721,6 +721,46 @@
});
};
const setupPlainTextPreserver = (editor) => {
const isTextLike = (model) => !!(model && model.is && (model.is('text') || model.is('button') || model.is('link')));
const lastContent = new Map();
const snapshotContent = (model) => {
const el = model.view && model.view.el;
const html = String(model.get ? (model.get('content') || '') : '').trim();
const inner = el && el.innerHTML ? String(el.innerHTML).trim() : '';
const text = el && el.textContent ? String(el.textContent).trim() : '';
const composite = html || inner || text;
return {
html: composite,
text,
};
};
const rememberIfPresent = (model) => {
if (!isTextLike(model)) return;
const snap = snapshotContent(model);
if (!snap.html) return;
lastContent.set(model.cid || model, snap);
};
const restoreIfEmpty = (model) => {
if (!isTextLike(model) || !model.get) return;
const current = snapshotContent(model);
if (current.html) {
rememberIfPresent(model);
return;
}
const stored = lastContent.get(model.cid || model);
if (!stored || !stored.html) return;
if (model.components && model.components().length) return;
try {
model.set('content', stored.html);
model.trigger && model.trigger('change:content');
} catch {}
};
editor.on('component:update', (model) => restoreIfEmpty(model));
editor.on('component:input', (model) => restoreIfEmpty(model));
editor.on('component:add', (model) => rememberIfPresent(model));
};
const setupTableBuilder = (editor) => {
const domc = editor.DomComponents;
if (!domc) return;
@@ -1024,6 +1064,7 @@
setupRichTextEditor(ed);
setupTableBuilder(ed);
setupPlainTextPreserver(ed);
loadDynamicFonts();
// Entfernt: jegliche Blur/RTE-Handler, die Inhalte verändern.