Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: allow cards to be created by Enter and Shift+Enter when the header of the column is focused

Adorian Doranff280acf4ac0
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index 6aaffb242d..b6c0f6fc01 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -525,7 +525,21 @@ export default function Column({
e.stopPropagation();
collapse();
}
- }, [ collapse, column, isCollapsed ]);
+
+ // Enter makes a card at the head of the column, Shift+Enter one at its foot. Ctrl+Enter
+ // inserts a column and is left to `keyboard.ts`, which also opens a collapsed column.
+ if (e.key === "Enter" && !e.ctrlKey && !isCollapsed && e.target === e.currentTarget) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ // A sorted column places its own cards, so the field opens at the foot either way.
+ if (e.shiftKey || isSorted) {
+ beginNewItem();
+ } else {
+ beginInsert(0);
+ }
+ }
+ }, [ beginInsert, beginNewItem, collapse, column, isCollapsed, isSorted ]);
const overlayHost = useContext(BoardOverlayHostContext);
/** Whether the heading holds the focus, which on mobile floats the column's rail. */
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index a184def521..0a3f19644d 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -2073,6 +2073,44 @@ describe("Board column rename", () => {
expect(content?.scrollTop).toBe(0);
});
+ /**
+ * A heading holds no card to insert beside, so the ends of the column are what Enter and
+ * Shift+Enter reach there.
+ */
+ it("opens the field at the head of the column for Enter on its heading", async () => {
+ const { container } = await setup();
+ const column = container.querySelectorAll<HTMLElement>(".board-column")[1];
+ const header = column.querySelector<HTMLElement>("h3");
+ const content = column.querySelector<HTMLElement>(".board-column-content");
+ if (!header || !content) throw new Error("expected a column with a heading");
+
+ await act(async () => {
+ header.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
+ await flush();
+ });
+
+ const drawn = [ ...content.querySelectorAll(".board-note, .board-new-item") ];
+ expect(drawn[0]?.classList.contains("board-new-item")).toBe(true);
+ expect(drawn[1]?.classList.contains("board-note")).toBe(true);
+ });
+
+ it("opens the field at the foot of the column for Shift+Enter on its heading", async () => {
+ const { container } = await setup();
+ const column = container.querySelectorAll<HTMLElement>(".board-column")[1];
+ const header = column.querySelector<HTMLElement>("h3");
+ if (!header) throw new Error("expected a column with a heading");
+
+ await act(async () => {
+ header.dispatchEvent(new KeyboardEvent(
+ "keydown", { key: "Enter", shiftKey: true, bubbles: true }));
+ await flush();
+ });
+
+ // The footer's own field, which stands outside the cards rather than among them.
+ expect(column.querySelector(".board-column-content .board-new-item")).toBeNull();
+ expect(column.querySelector(".board-new-item.editing")).toBeTruthy();
+ });
+
/**
* The same field wherever it stands, so a card inserted between two others is named, iconed and
* made from a template the way a card added below the column is.
diff --git a/apps/client/src/widgets/collections/board/keyboard.spec.tsx b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
index d834112db6..d1e75bc0ed 100644
--- a/apps/client/src/widgets/collections/board/keyboard.spec.tsx
+++ b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
@@ -515,13 +515,16 @@ describe("Board keyboard", () => {
.toBe(true);
});
- it("leaves Enter alone on a column that is not collapsed", async () => {
+ /** The column keeps its cards: only a collapsed heading answers Enter with an expand. */
+ it("makes a card instead of expanding a column that is not collapsed", async () => {
const board = await renderBoard();
focusHeader(board, 1);
press(board, "Enter");
+ await act(async () => { await flush(); });
- expect(document.activeElement).toBe(columnAt(board, 1).querySelector("h3"));
+ expect(saved).toHaveLength(0);
+ expect(columnAt(board, 1).querySelector(".board-new-item.inserting")).toBeTruthy();
expect(columnAt(board, 1).querySelectorAll(".board-note")).toHaveLength(1);
});
});
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html
index 5095081d1e..d85998e0aa 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Collections/Kanban Board.html
@@ -97,6 +97,8 @@
<li>To rename a column or a note, press F2 while it is focused.</li>
<li>To open a specific note or create a new item, press Enter while it is
focused.</li>
+ <li>To create a card at the top of a column, press Enter while its header
+ is focused; Shift+Enter creates one at the bottom.</li>
<li>To collapse or expand a column, press Space while its header is
focused.</li>
<li>To dismiss a rename of a note or a column, press Escape.</li>
diff --git a/docs/User Guide/User Guide/Collections/Kanban Board.md b/docs/User Guide/User Guide/Collections/Kanban Board.md
index ff718c319a..5bd3fd7db0 100644
--- a/docs/User Guide/User Guide/Collections/Kanban Board.md
+++ b/docs/User Guide/User Guide/Collections/Kanban Board.md
@@ -65,6 +65,7 @@ The board view has mild support for keyboard-based navigation:
* Use Tab and Shift+Tab to navigate between column titles, notes and the “New item” button for each of the columns, in sequential order.
* To rename a column or a note, press F2 while it is focused.
* To open a specific note or create a new item, press Enter while it is focused.
+* To create a card at the top of a column, press Enter while its header is focused; Shift+Enter creates one at the bottom.
* To collapse or expand a column, press Space while its header is focused.
* To dismiss a rename of a note or a column, press Escape.