Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: make Ctrl+A to select all the items within a column

Adorian Doran38ee399cd58a
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index d695d3e2c9..bea337c440 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3514,7 +3514,10 @@
"move_across": "Move to the previous / next column",
"move_to_end_column": "Move to the first / last column",
"move_column": "Move the column left / right",
- "move_column_to_edge": "Move the column to the far left / right"
+ "move_column_to_edge": "Move the column to the far left / right",
+ "selection": "Selection",
+ "select_column": "Select every item of the column",
+ "clear_selection": "Clear the selection"
},
"status-alias": "Status",
"filter-placeholder": "Filter board...",
diff --git a/apps/client/src/widgets/collections/board/card.spec.tsx b/apps/client/src/widgets/collections/board/card.spec.tsx
index 965c6632e5..133599500d 100644
--- a/apps/client/src/widgets/collections/board/card.spec.tsx
+++ b/apps/client/src/widgets/collections/board/card.spec.tsx
@@ -298,6 +298,19 @@ describe("Board card", () => {
expect(selectedCards()).toEqual([ "Extra 2" ]);
});
+ it("takes every card of the column focus is in on Ctrl+A", async () => {
+ const { first, extra } = await renderBoard([ "Done" ]);
+
+ await act(async () => {
+ card(first).focus();
+ press(card(first), "a", { ctrlKey: true });
+ });
+
+ // The card in the other column is left alone, whichever way the columns are drawn.
+ expect(selectedCards()).toEqual([ "First", "Second" ]);
+ expect(cardClasses(extra[0])).not.toContain("selected");
+ });
+
it("gives the whole selection up on a plain click, which opens the note", async () => {
const { first, second } = await renderBoard();
const openInPopup = vi.spyOn(appContext, "triggerCommand").mockReturnValue(undefined);
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 8f308bc8a5..f6bd0a61d3 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -1124,7 +1124,8 @@ describe("Board column rename", () => {
expect(sections.map(section => section.titleKey)).toEqual([
"board_view.hints.navigation",
"board_view.hints.editing",
- "board_view.hints.moving"
+ "board_view.hints.moving",
+ "board_view.hints.selection"
]);
// Every key the board answers for is spoken for, and none it does not.
expect(sections.flatMap(section => section.hints)).toEqual([
@@ -1155,7 +1156,9 @@ describe("Board column rename", () => {
{
keys: [ "Ctrl+Alt+Home", "Ctrl+Alt+End" ],
labelKey: "board_view.hints.move_column_to_edge"
- }
+ },
+ { keys: [ "Ctrl+A" ], labelKey: "board_view.hints.select_column" },
+ { keys: [ "Escape" ], labelKey: "board_view.hints.clear_selection" }
]);
});
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index f7de8c7f83..0047ad0eca 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -298,6 +298,13 @@ const BOARD_HINTS: ShortcutHintDefinition = [
labelKey: "board_view.hints.move_column_to_edge"
}
]
+ },
+ {
+ titleKey: "board_view.hints.selection",
+ hints: [
+ { keys: [ "Ctrl+A" ], labelKey: "board_view.hints.select_column" },
+ { keys: [ "Escape" ], labelKey: "board_view.hints.clear_selection" }
+ ]
}
];
@@ -1040,6 +1047,7 @@ export default function BoardView({
byColumn,
api,
moveColumn: handleColumnDrop,
+ selection,
insertColumn: useCallback(async (relativeTo: string, direction: "before" | "after") => {
setColumnNameToEdit(await api.insertColumn(relativeTo, direction));
}, [ api ])
diff --git a/apps/client/src/widgets/collections/board/keyboard.ts b/apps/client/src/widgets/collections/board/keyboard.ts
index 01d568c702..c30fd9f66f 100644
--- a/apps/client/src/widgets/collections/board/keyboard.ts
+++ b/apps/client/src/widgets/collections/board/keyboard.ts
@@ -4,6 +4,7 @@ import { useCallback, useLayoutEffect, useRef } from "preact/hooks";
import branches from "../../../services/branches";
import { FLIP_SETTLE_MS } from "../../react/flip";
+import { SelectionStore } from "../../react/selection";
import BoardApi from "./api";
import { ColumnMap } from "./data";
@@ -70,6 +71,8 @@ export interface BoardKeyboardOptions {
* for the focus to land on.
*/
setActiveColumn: (column: string) => void;
+ /** Which cards are picked out, which Ctrl+A fills with the focused column. */
+ selection: SelectionStore;
}
/**
@@ -88,7 +91,7 @@ export interface BoardKeyboardOptions {
* would otherwise be left focused on nothing.
*/
export function useBoardKeyboard({
- containerRef, columns, byColumn, api, moveColumn, insertColumn, setActiveColumn
+ containerRef, columns, byColumn, api, moveColumn, insertColumn, setActiveColumn, selection
}: BoardKeyboardOptions) {
const pendingFocus = useRef<PendingFocus | null>(null);
@@ -162,6 +165,14 @@ export function useBoardKeyboard({
if (!spot) return;
if (e.ctrlKey) {
+ // Every card of the column focus is in, wherever inside it focus sits. The button that
+ // adds a column stands in none, and Ctrl+A there is the page's own.
+ if (e.key === "a" && !e.altKey && !e.shiftKey && spot.kind !== "add-column") {
+ take(e);
+ selection.selectAll(api.getColumnNoteIds(columns[spot.column]));
+ return;
+ }
+
// A column beside the one focus is in, wherever inside it focus sits. The button that
// adds a column stands beside none, and is the plain way to add one at the end anyway.
if (e.key === "Enter" && !e.altKey && spot.kind !== "add-column") {
diff --git a/apps/client/src/widgets/react/selection.spec.tsx b/apps/client/src/widgets/react/selection.spec.tsx
index c40092cd76..9acc30f143 100644
--- a/apps/client/src/widgets/react/selection.spec.tsx
+++ b/apps/client/src/widgets/react/selection.spec.tsx
@@ -41,6 +41,19 @@ describe("SelectionStore", () => {
expect(store.anchor).toBe("a");
});
+ it("takes a whole list at once, with the anchor on its first item", () => {
+ store.toggle("e");
+ store.selectAll([ "a", "b", "c" ]);
+
+ expect(selected()).toEqual([ "a", "b", "c" ]);
+ expect(store.anchor).toBe("a");
+
+ // A column holding nothing leaves the selection empty rather than as it was.
+ store.selectAll([]);
+ expect(selected()).toEqual([]);
+ expect(store.anchor).toBeNull();
+ });
+
it("gives up everything at once", () => {
store.toggle("b");
store.clear();
diff --git a/apps/client/src/widgets/react/selection.ts b/apps/client/src/widgets/react/selection.ts
index 9af79f62b4..825ee77f0f 100644
--- a/apps/client/src/widgets/react/selection.ts
+++ b/apps/client/src/widgets/react/selection.ts
@@ -51,6 +51,17 @@ export class SelectionStore {
this.replace(next);
}
+ /**
+ * Selects a whole list at once, dropping whatever else was selected. Ctrl+A does this.
+ *
+ * The anchor lands on the first of them, so a Shift+Click afterwards ranges from the head of
+ * what was just taken.
+ */
+ selectAll(keys: string[]) {
+ this.anchorKey = keys[0] ?? null;
+ this.replace(new Set(keys));
+ }
+
/**
* Selects everything between the anchor and `to`, dropping whatever else was selected.
*