Skip to content

Build your personal knowledge base with Trilium Notes

text editor/collapsible: fix an issue

Adorian Doranc0db850b187e
diff --git a/packages/ckeditor5-collapsible/src/collapsible-editing.ts b/packages/ckeditor5-collapsible/src/collapsible-editing.ts
index 59ada1bf73..0d47f6cc8a 100644
--- a/packages/ckeditor5-collapsible/src/collapsible-editing.ts
+++ b/packages/ckeditor5-collapsible/src/collapsible-editing.ts
@@ -717,19 +717,24 @@ export default class CollapsibleEditing extends Plugin {
let ready = false;
// Trilium loads note content via `editor.setData(...)` after the editor
// is ready, so the change:data that follows is a wholesale data load —
- // not user-initiated insertions. Mark it so we don't auto-open every
- // existing collapsible in the loaded note.
- let suppressNextChange = false;
+ // not user-initiated insertions. Bracket the entire setData call with
+ // `loading=true/false` (highest fires before the data is written,
+ // lowest after everything setData triggered synchronously) so every
+ // change:data that fires inside is covered — not just the first one.
+ // The CKEditor public API doesn't guarantee setData emits exactly one
+ // change:data, so a single-shot flag would leak follow-ups.
+ let loading = false;
// Accumulate across `change:data` events: if two events fire in the
// same tick (separate model transactions), each restarting the timer
// would otherwise drop the previous batch on the floor.
const pendingOpen = new Set<any>();
this.listenTo(editor, "ready", () => { ready = true; });
- this.listenTo(editor.data, "set", () => { suppressNextChange = true; }, { priority: "high" });
+ this.listenTo(editor.data, "set", () => { loading = true; }, { priority: "highest" });
+ this.listenTo(editor.data, "set", () => { loading = false; }, { priority: "lowest" });
this.listenTo(editor.model.document, "change:data", () => {
- if (suppressNextChange) { suppressNextChange = false; return; }
+ if (loading) return;
if (!ready) return;
for (const entry of editor.model.document.differ.getChanges()) {
if (entry.type !== "insert") continue;