Skip to content

Build your personal knowledge base with Trilium Notes

text editor/collapsible: add placeholder for content

Adorian Doran859d53986746
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 2a606b8a37..f0a65a49cf 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2676,8 +2676,9 @@
},
"text-editor": {
"checkbox-tooltip": "Right click for more task states.\nPress {{shortcut}} to cycle between states.",
+ "collapsible-body-placeholder": "Type the content here...",
"collapsible-button-label": "Collapsible block",
- "collapsible-title-placeholder": "Title",
+ "collapsible-title-placeholder": "Summary",
"collapsible-toggle-label": "Toggle collapsible block",
"collapsible-tooltip": "Click on the arrow or press {{shortcut}} to collapse/expand.",
"edit-states-tooltip": "Edit task states",
diff --git a/packages/ckeditor5-collapsible/src/collapsible-editing.ts b/packages/ckeditor5-collapsible/src/collapsible-editing.ts
index df9422221d..f0035ecec2 100644
--- a/packages/ckeditor5-collapsible/src/collapsible-editing.ts
+++ b/packages/ckeditor5-collapsible/src/collapsible-editing.ts
@@ -37,6 +37,7 @@ export default class CollapsibleEditing extends Plugin {
this.editor.commands.add("collapsible", new CollapsibleCommand(this.editor));
this.registerSchema();
this.registerConversion();
+ this.registerBodyPlaceholder();
this.registerKeyHandlers();
this.registerClickHandler();
this.registerDomListeners();
@@ -210,6 +211,39 @@ export default class CollapsibleEditing extends Plugin {
}
}
+ // -----------------------------------------------------------------
+ // Body placeholder
+ // -----------------------------------------------------------------
+
+ /**
+ * Show a "Content" placeholder on empty body paragraphs of a <details>.
+ * Applied per paragraph via an editing-downcast event listener, so each
+ * body paragraph manages its own emptiness independently — the placeholder
+ * appears on whichever body paragraphs happen to be empty (typically just
+ * the single empty one in a freshly-inserted collapsible).
+ */
+ private bodyPlaceholdersApplied = new WeakSet<any>();
+
+ private registerBodyPlaceholder() {
+ const editor = this.editor;
+ const t = this.translate();
+ editor.conversion.for("editingDowncast").add((dispatcher: any) => {
+ dispatcher.on("insert:paragraph", (_evt: any, data: any, conversionApi: any) => {
+ const paragraph = data.item;
+ if (!paragraph.parent?.is("element", "details")) return;
+ const view = conversionApi.mapper.toViewElement(paragraph);
+ if (!view || this.bodyPlaceholdersApplied.has(view)) return;
+ enableViewPlaceholder({
+ view: editor.editing.view,
+ element: view,
+ text: t("text-editor.collapsible-body-placeholder"),
+ keepOnFocus: true
+ });
+ this.bodyPlaceholdersApplied.add(view);
+ }, { priority: "low" });
+ });
+ }
+
// -----------------------------------------------------------------
// View-event key handlers (Enter, Delete, ArrowUp)
// -----------------------------------------------------------------
diff --git a/packages/ckeditor5-collapsible/theme/collapsible.css b/packages/ckeditor5-collapsible/theme/collapsible.css
index 7567261e8d..502ec87574 100644
--- a/packages/ckeditor5-collapsible/theme/collapsible.css
+++ b/packages/ckeditor5-collapsible/theme/collapsible.css
@@ -89,6 +89,11 @@
*/
.ck-editor__editable details.trilium-collapsible {
+
+ .ck-placeholder::before {
+ opacity: 0.5;
+ }
+
> summary {
cursor: text;
list-style: none;
@@ -103,7 +108,6 @@
* push it past the arrow so it aligns with where the typed title will appear. */
&.ck-placeholder::before {
left: var(--_arrow-gap);
- opacity: 0.5;
}
/* The arrow lands wherever in DOM the conversion mapper ends up putting it,