Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/multicolumn layout: tweak the appearance

Adorian Doran763aaa0b6eae
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 2e68efc5b3..290316d120 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -4407,7 +4407,8 @@
"0-columns-layout": "%0 columns layout",
"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"
+ "remove-layout": "Remove layout",
+ "type-content-here": "Type content here…"
},
"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/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Multicolumn layout.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Multicolumn layout.html
index 72f9b58893..4bd9926f2b 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Multicolumn layout.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Multicolumn layout.html
@@ -1,9 +1,10 @@
<p>A multicolumn layout arranges content in two to four columns, side by
side. A column can hold any kind of content, including tables, images and
another multicolumn layout.</p>
-<p>The borders around the columns are only a guide while editing. In <a href="#root/_help_CoFPLs3dRlXc">read-only notes</a>, <a
- href="#root/_help_R9pX4DGra2Vt">shared notes</a> and printouts, the columns
- have no borders, and their text lines up with the rest of the note.</p>
+<p>The columns have no borders; only the space between them sets them apart.
+ While editing, an empty column shows the hint <em>Type content here…</em>.
+ In <a href="#root/_help_CoFPLs3dRlXc">read-only notes</a>, <a href="#root/_help_R9pX4DGra2Vt">shared notes</a> and
+ printouts, the text of the columns lines up with the rest of the note.</p>
<h2>Inserting a layout</h2>
<ul>
<li>In the formatting bar, go to <em>Insert</em> → <span class="tn-icon cke cke-trilium-multicolumn"></span> <em>Multiple column layout</em> to
@@ -58,13 +59,13 @@
<h2>Narrow screens</h2>
<p>When a layout has too little room for its columns (narrower than about
500 pixels, such as on a phone), the columns are stacked one below the
- other. While editing, alternating background colors take the place of the
- borders. This applies to each layout on its own, so a layout inside a narrow
- column is stacked while the outer one stays side by side.</p>
+ other. While editing, alternating background colors tell the columns apart.
+ This applies to each layout on its own, so a layout inside a narrow column
+ is stacked while the outer one stays side by side.</p>
<h2>Printing and exporting</h2>
<ul>
<li>When printing or <a href="#root/_help_NRnIZmSMc5sj">exporting to PDF</a>,
- the columns are printed side by side, without borders.</li>
+ the columns are printed side by side.</li>
<li>Markdown has no columns, so Markdown export writes the content of the
columns one after another.</li>
</ul>
\ No newline at end of file
diff --git a/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.md b/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.md
index 078f4e9fbc..02404a4627 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Multicolumn layout.md
@@ -1,7 +1,7 @@
# Multicolumn layout
A multicolumn layout arranges content in two to four columns, side by side. A column can hold any kind of content, including tables, images and another multicolumn layout.
-The borders around the columns are only a guide while editing. In [read-only notes](../../Basic%20Concepts%20and%20Features/Notes/Read-Only%20Notes.md), [shared notes](../../Advanced%20Usage/Sharing.md) and printouts, the columns have no borders, and their text lines up with the rest of the note.
+The columns have no borders; only the space between them sets them apart. While editing, an empty column shows the hint _Type content here…_. In [read-only notes](../../Basic%20Concepts%20and%20Features/Notes/Read-Only%20Notes.md), [shared notes](../../Advanced%20Usage/Sharing.md) and printouts, the text of the columns lines up with the rest of the note.
## Inserting a layout
@@ -30,9 +30,9 @@ While the cursor is inside a layout, a toolbar appears above it with a button th
## Narrow screens
-When a layout has too little room for its columns (narrower than about 500 pixels, such as on a phone), the columns are stacked one below the other. While editing, alternating background colors take the place of the borders. This applies to each layout on its own, so a layout inside a narrow column is stacked while the outer one stays side by side.
+When a layout has too little room for its columns (narrower than about 500 pixels, such as on a phone), the columns are stacked one below the other. While editing, alternating background colors tell the columns apart. This applies to each layout on its own, so a layout inside a narrow column is stacked while the outer one stays side by side.
## Printing and exporting
-* When printing or [exporting to PDF](../../Basic%20Concepts%20and%20Features/Notes/Printing%20%26%20Exporting%20as%20PDF.md), the columns are printed side by side, without borders.
+* When printing or [exporting to PDF](../../Basic%20Concepts%20and%20Features/Notes/Printing%20%26%20Exporting%20as%20PDF.md), the columns are printed side by side.
* Markdown has no columns, so Markdown export writes the content of the columns one after another.
\ No newline at end of file
diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.spec.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.spec.ts
index feafc1568a..e58c13764f 100644
--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.spec.ts
+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.spec.ts
@@ -84,6 +84,40 @@ describe("MulticolumnEditing", () => {
});
});
+ describe("placeholder", () => {
+ /** Whether the first block of each column shows the placeholder. */
+ 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);
+ }
+
+ it("shows in each column holding only an empty block, until text is typed there", () => {
+ editor.editing.view.document.isFocused = true;
+ setModelData(editor.model,
+ "<multicolumnLayout columnRatios=\"1-1-1-1\">" +
+ "<multicolumnColumn><paragraph>Text</paragraph></multicolumnColumn>" +
+ "<multicolumnColumn><paragraph>[]</paragraph></multicolumnColumn>" +
+ "<multicolumnColumn>" +
+ "<paragraph></paragraph><paragraph>Text</paragraph>" +
+ "</multicolumnColumn>" +
+ "<multicolumnColumn></multicolumnColumn>" +
+ "</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…");
+
+ editor.model.change(writer => {
+ editor.model.insertContent(writer.createText("Typed"));
+ });
+
+ expect(placeholders()).toEqual([false, false, false, true]);
+ });
+ });
+
describe("schema", () => {
it("allows a layout at the top level, in a column, a tab panel and a collapsible", () => {
const schema = editor.model.schema;
diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts
index 6c380ecff8..cde86188f4 100644
--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts
+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_editing.ts
@@ -1,11 +1,14 @@
import {
+ enableViewPlaceholder,
type ModelElement,
type ModelNode,
type ModelPosition,
type ModelWriter,
+ type PlaceholderableViewElement,
Plugin,
toWidget,
toWidgetEditable,
+ type ViewEditableElement,
type ViewElement,
Widget
} from "ckeditor5";
@@ -103,7 +106,15 @@ export default class MulticolumnEditing extends Plugin {
conversion.for("editingDowncast").elementToElement({
model: ELEMENTS.column,
view: (_model, { writer }) => {
- const section = writer.createEditableElement("section");
+ const section: ViewEditableElement & PlaceholderableViewElement =
+ writer.createEditableElement("section");
+ section.placeholder = t("Type content here…");
+ enableViewPlaceholder({
+ view: editor.editing.view,
+ element: section,
+ isDirectHost: false,
+ keepOnFocus: true
+ });
return toWidgetEditable(section, writer, { label: t("Column") });
}
});
diff --git a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts
index 6c7670268b..da19f6fe11 100644
--- a/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts
+++ b/packages/ckeditor5/src/plugins/multicolumn/multicolumn_layout.spec.ts
@@ -1,4 +1,4 @@
-import { Essentials, Paragraph, Table } from "ckeditor5";
+import { _setModelData as setModelData, Essentials, Paragraph, Table } from "ckeditor5";
import editorStylesheetUrl from "ckeditor5/ckeditor5.css?url";
import { beforeAll, describe, expect, it, onTestFinished } from "vitest";
@@ -102,48 +102,34 @@ describe("multicolumn layout styles", () => {
}
});
- it("rounds the widget and the outer corners of the columns, in either direction", async () => {
+ it("rounds the widget and pads its columns only in the editor, without borders", async () => {
const editor = await createTestEditor([Essentials, Paragraph, Multicolumn]);
const editable = editor.ui.view.editable.element as HTMLElement;
editable.style.width = "800px";
- editor.setData(layoutHtml("1-1-1-1", ["<p>A</p>", "<p>B</p>", "<p>C</p>", "<p>D</p>"]));
+ editor.editing.view.document.isFocused = true;
+ setModelData(editor.model,
+ "<multicolumnLayout columnRatios=\"1-1\">" +
+ "<multicolumnColumn><paragraph>[]A</paragraph></multicolumnColumn>" +
+ "<multicolumnColumn><paragraph>B</paragraph></multicolumnColumn>" +
+ "</multicolumnLayout>"
+ );
const widget = editable.querySelector(".trilium-multicolumn-layout");
-
- expect([widget, ...columnsOf(widget)].map(cornersOf)).toEqual([
- "8px 8px 8px 8px",
- "8px 0px 0px 8px",
- "0px 0px 0px 0px",
- "0px 0px 0px 0px",
- "0px 8px 8px 0px"
- ]);
-
- const rtlEditor = await createTestEditor([Essentials, Paragraph, Multicolumn], {
- language: { content: "ar" }
- });
- const rtlEditable = rtlEditor.ui.view.editable.element as HTMLElement;
- rtlEditable.style.width = "800px";
- rtlEditor.setData(layoutHtml("1-1", ["<p>A</p>", "<p>B</p>"]));
- expect(rtlEditable.dir).toBe("rtl");
- const columns = columnsOf(rtlEditable.querySelector(".trilium-multicolumn-layout"));
- expect(columns.map(cornersOf)).toEqual(["0px 8px 8px 0px", "8px 0px 0px 8px"]);
- });
-
- it("borders and pads the columns only in the editor", async () => {
- const editor = await createTestEditor([Essentials, Paragraph, Multicolumn]);
- const editable = editor.ui.view.editable.element as HTMLElement;
- editable.style.width = "800px";
- editor.setData(layoutHtml("1-1", ["<p>A</p>", "<p>B</p>"]));
- const editingColumns = columnsOf(editable.querySelector(".trilium-multicolumn-layout"));
+ const editingColumns = columnsOf(widget);
const container = renderContent(layoutHtml("1-1", ["<p>A</p>", "<p>B</p>"]), 800);
const savedColumns = columnsOf(container.querySelector(".trilium-multicolumn-layout"));
- expect(editingColumns).toHaveLength(2);
+ expect(cornersOf(widget)).toBe("8px 8px 8px 8px");
+ expect(editingColumns.map(column =>
+ column.classList.contains("ck-editor__nested-editable_focused")))
+ .toEqual([true, false]);
expect(savedColumns).toHaveLength(2);
for (const column of editingColumns) {
const style = getComputedStyle(column);
- expect([style.borderTopWidth, style.paddingLeft, style.paddingRight])
- .toEqual(["1px", "16px", "16px"]);
+ expect([style.borderTopWidth, style.borderLeftWidth, style.boxShadow])
+ .toEqual(["0px", "0px", "none"]);
+ expect([style.paddingLeft, style.paddingRight, cornersOf(column)])
+ .toEqual(["16px", "16px", "0px 0px 0px 0px"]);
}
for (const column of savedColumns) {
const style = getComputedStyle(column);
@@ -153,6 +139,43 @@ describe("multicolumn layout styles", () => {
}
});
+ it("outlines the widget like a selected one while the caret is in a column", async () => {
+ const editor = await createTestEditor([Essentials, Paragraph, Multicolumn]);
+ const editable = editor.ui.view.editable.element as HTMLElement;
+ const viewDocument = editor.editing.view.document;
+ viewDocument.isFocused = true;
+ setModelData(editor.model,
+ "<paragraph>[]Before</paragraph>" +
+ "<multicolumnLayout columnRatios=\"1-1\">" +
+ "<multicolumnColumn><paragraph>A</paragraph></multicolumnColumn>" +
+ "<multicolumnColumn><paragraph>B</paragraph></multicolumnColumn>" +
+ "</multicolumnLayout>"
+ );
+ const widget = editable.querySelector(".trilium-multicolumn-layout") as HTMLElement;
+ const outline = () => {
+ const style = getComputedStyle(widget);
+ return `${style.outlineStyle} ${style.outlineWidth} ${style.outlineColor}`;
+ };
+ document.documentElement.style.setProperty("--link-color", "rgb(12, 34, 56)");
+ onTestFinished(() => {
+ document.documentElement.style.removeProperty("--link-color");
+ });
+
+ expect(outline()).toBe("solid 3px rgba(0, 0, 0, 0)");
+
+ editor.model.change(writer => {
+ const root = editor.model.document.getRoot();
+ if (root) {
+ writer.setSelection(writer.createPositionFromPath(root, [1, 1, 0, 0]));
+ }
+ });
+ await expect.poll(outline).toBe("solid 3px rgb(12, 34, 56)");
+
+ viewDocument.isFocused = false;
+ editor.editing.view.forceRender();
+ await expect.poll(outline).toBe("solid 3px rgba(0, 0, 0, 0)");
+ });
+
it("lines the text of saved content up with the content around it, 2em apart", () => {
const html = "<p>Outside</p>" +
layoutHtml("1-2-1", ["<p>A</p>", "<p>B</p>", "<p>C</p>"]);
diff --git a/packages/ckeditor5/src/theme/multicolumn.css b/packages/ckeditor5/src/theme/multicolumn.css
index 3a22e3d34a..51d44a74c5 100644
--- a/packages/ckeditor5/src/theme/multicolumn.css
+++ b/packages/ckeditor5/src/theme/multicolumn.css
@@ -1,5 +1,5 @@
:where(:root) {
- --multicolumn-layout-border-color: var(--main-border-color, var(--ck-color-base-border));
+ --multicolumn-layout-focus-border-color: var(--link-color, var(--ck-color-focus-border));
--multicolumn-layout-stacked-background: var(--accented-background-color,
var(--ck-color-base-foreground));
--multicolumn-layout-border-radius: 8px;
@@ -50,20 +50,15 @@
column-gap: 12px;
border-radius: var(--multicolumn-layout-border-radius);
- & > section {
- border: 1px solid var(--multicolumn-layout-border-color);
- border-radius: var(--multicolumn-layout-border-radius);
- padding-inline: 1rem;
-
- &:not(:first-of-type) {
- border-start-start-radius: 0;
- border-end-start-radius: 0;
- }
+ &:has(.ck-editor__nested-editable_focused) {
+ outline: var(--ck-widget-outline-thickness, 3px) solid
+ var(--multicolumn-layout-focus-border-color);
+ }
- &:not(:last-of-type) {
- border-start-end-radius: 0;
- border-end-end-radius: 0;
- }
+ & > section.ck-editor__nested-editable {
+ border: 0;
+ padding-inline: 1rem;
+ box-shadow: none;
}
}
}
@@ -73,12 +68,7 @@
grid-column: 1 / -1;
}
- .ck-content .trilium-multicolumn-layout.ck-widget > section {
- border: 0;
- border-radius: 0;
-
- &:nth-of-type(even) {
- background: var(--multicolumn-layout-stacked-background);
- }
+ .ck-content .trilium-multicolumn-layout.ck-widget > section:nth-of-type(even) {
+ background: var(--multicolumn-layout-stacked-background);
}
}