Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/text editor: update the multicolumn layout placeholder text
Adorian Doranc0019dad19e0
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 0e8b1a4edb..cdec9fd4bb 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -4443,7 +4443,10 @@"arrange-content-in-0-equal-columns-side-by-side": "Arrange content in %0 equal columns side by side.","0-columns-1": "%0 columns (%1)","remove-layout": "Remove layout",- "type-content-here": "Type content here…"+ "type-the-content-of-the-first-column": "Type the content of the first column",+ "type-the-content-of-the-second-column": "Type the content of the second column",+ "type-the-content-of-the-third-column": "Type the content of the third column",+ "type-the-content-of-the-fourth-column": "Type the content of the fourth column"},"task-state-dropped-title": "Invalid task states","task-state-dropped-message_one": "A custom task state definition is invalid and was ignored.",diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.spec.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.spec.tsindex e58c13764f..025b0258b6 100644--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.spec.ts+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.spec.ts@@ -85,12 +85,16 @@ describe("MulticolumnEditing", () => {});describe("placeholder", () => {- /** Whether the first block of each column shows the placeholder. */+ /** The placeholder each column shows in its first block, or `null` for none. */function placeholders() {const root = editor.editing.view.getDomRoot();const columns = root?.querySelectorAll(".trilium-multicolumn-layout > section") ?? [];- return [...columns].map(column =>- column.firstElementChild?.classList.contains("ck-placeholder") ?? false);+ return [...columns].map(column => {+ const block = column.firstElementChild;+ return block?.classList.contains("ck-placeholder")+ ? block.getAttribute("data-placeholder")+ : null;+ });}it("shows in each column holding only an empty block, until text is typed there", () => {@@ -106,15 +110,37 @@ describe("MulticolumnEditing", () => {"</multicolumnLayout>");- expect(placeholders()).toEqual([false, true, false, true]);- const host = editor.editing.view.getDomRoot()?.querySelector(".ck-placeholder");- expect(host?.getAttribute("data-placeholder")).toBe("Type content here…");+ expect(placeholders()).toEqual([+ null,+ "Type the content of the second column",+ null,+ "Type the content of the fourth column"+ ]);editor.model.change(writer => {editor.model.insertContent(writer.createText("Typed"));});- expect(placeholders()).toEqual([false, false, false, true]);+ expect(placeholders()).toEqual([+ null, null, null, "Type the content of the fourth column"+ ]);+ });++ it("names the position of each column, including one added to the layout", () => {+ setModelData(editor.model,+ "<multicolumnLayout columnRatios=\"1-1\">" ++ "<multicolumnColumn><paragraph>[]</paragraph></multicolumnColumn>" ++ "<multicolumnColumn><paragraph></paragraph></multicolumnColumn>" ++ "</multicolumnLayout>"+ );++ editor.execute("columnLayout", { value: "1-1-1" });++ expect(placeholders()).toEqual([+ "Type the content of the first column",+ "Type the content of the second column",+ "Type the content of the third column"+ ]);});});diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.tsindex cde86188f4..00134dde0b 100644--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts@@ -1,5 +1,6 @@import {enableViewPlaceholder,+ type LocaleTranslate,type ModelElement,type ModelNode,type ModelPosition,@@ -105,10 +106,10 @@ export default class MulticolumnEditing extends Plugin {});conversion.for("editingDowncast").elementToElement({model: ELEMENTS.column,- view: (_model, { writer }) => {+ view: (column, { writer }) => {const section: ViewEditableElement & PlaceholderableViewElement =writer.createEditableElement("section");- section.placeholder = t("Type content here…");+ section.placeholder = getColumnPlaceholder(t, column.index ?? 0);enableViewPlaceholder({view: editor.editing.view,element: section,@@ -152,6 +153,19 @@ export default class MulticolumnEditing extends Plugin {}}+/**+ * The placeholder of the column at `index`, which names its position. A layout has at most+ * `MAX_COLUMNS` (four) columns.+ */+function getColumnPlaceholder(t: LocaleTranslate, index: number) {+ switch (index) {+ case 0: return t("Type the content of the first column");+ case 1: return t("Type the content of the second column");+ case 2: return t("Type the content of the third column");+ default: return t("Type the content of the fourth column");+ }+}+/** Matches a `<section>` directly inside a layout. Columns have no class of their own. */function matchColumn(element: ViewElement) {const parent = element.parent;