This commit is contained in:
2026-01-27 01:36:23 +01:00
parent b66d0c5d49
commit cf476632e2
3 changed files with 25 additions and 15 deletions

View File

@@ -372,28 +372,37 @@
el.__bridgeLastNormalized = snap.normalized;
}
};
const syncTextFromView = (model) => {
const target = resolveTextModel(model);
if (!isTextLike(target) || !target.view || !target.view.el) return;
const html = String(target.view.el.innerHTML || '').trim();
if (!html) return;
const current = target.get ? String(target.get('content') || '').trim() : '';
if (current === html) return;
try {
syncing.add(target);
if (target.components) {
const comps = target.components();
if (comps && comps.length) comps.reset();
}
if (target.set) target.set('content', html);
target.trigger && target.trigger('change:content');
} catch {} finally {
syncing.delete(target);
}
};
const rememberIfPresent = (model) => {
const target = resolveTextModel(model);
if (!isTextLike(target)) return;
const snap = snapshotContent(target);
if (!snap.normalized) return;
if (!syncing.has(target)) {
const currentContent = target.get ? String(target.get('content') || '').trim() : '';
if (currentContent !== snap.html) {
try {
syncing.add(target);
if (target.set) target.set('content', snap.html);
if (target.components) target.components(snap.html);
} catch {} finally {
syncing.delete(target);
}
}
}
if (!syncing.has(target)) syncTextFromView(target);
storeSnapshot(target, snap);
};
const restoreIfEmpty = (model) => {
const target = resolveTextModel(model);
if (!isTextLike(target) || !target.get) return;
if (!syncing.has(target)) syncTextFromView(target);
const current = snapshotContent(target);
if (current.normalized) {
rememberIfPresent(target);