Skip to content

Build your personal knowledge base with Trilium Notes

text editor/collapsible: fix another issue with caret navigation

Adorian Dorana0f88e807bfc
diff --git a/packages/ckeditor5-collapsible/src/collapsibleediting.ts b/packages/ckeditor5-collapsible/src/collapsibleediting.ts
index e464197c20..343b3e5761 100644
--- a/packages/ckeditor5-collapsible/src/collapsibleediting.ts
+++ b/packages/ckeditor5-collapsible/src/collapsibleediting.ts
@@ -343,6 +343,23 @@ export default class CollapsibleEditing extends Plugin {
return;
}
+ // Collapsed: drop a new paragraph after the whole block (or reuse one if
+ // there's already an empty paragraph there) — entering the hidden body
+ // would silently lose the caret.
+ if (!isDetailsOpen(details)) {
+ editor.model.change(writer => {
+ const next = details.nextSibling;
+ if (next?.is("element", "paragraph") && next.isEmpty) {
+ writer.setSelection(next, 0);
+ } else {
+ const newParagraph = writer.createElement("paragraph");
+ writer.insert(newParagraph, writer.createPositionAfter(details));
+ writer.setSelection(newParagraph, 0);
+ }
+ });
+ return;
+ }
+
const firstBodyBlock = summary.nextSibling;
if (firstBodyBlock && firstBodyBlock.is("element")) {
editor.model.change(writer => {