Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix an issue

Adorian Doran11bef09f299b
diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.ts
index d4fd6bb2c4..3e5afce0f6 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -525,6 +525,22 @@ describe("Board item context menu", () => {
expect(focusCard).toHaveBeenCalled();
});
+ /** The group still holds the two inserts, so the divider that heads it stays. */
+ it("keeps the divider while the column is arranged by hand", () => {
+ const items = openItemMenu({
+ columns: [],
+ isColumnArchived: () => false,
+ getColumnIcon: () => DEFAULT_COLUMN_ICON,
+ getColumnColorClass: () => "",
+ isFirstInColumn: () => true
+ } as unknown as BoardApi);
+
+ const at = items.findIndex(item => item && "uiIcon" in item
+ && item.uiIcon === "bx bx-rename");
+ expect(items[at + 1]).toMatchObject({ kind: "separator" });
+ expect(items[at + 2]).toMatchObject({ uiIcon: "bx bx-list-plus" });
+ });
+
it("says nothing about moving up the card already at the head", () => {
const api = {
columns: [],
@@ -552,14 +568,19 @@ describe("Board item context menu", () => {
isFirstInColumn: () => false
} as unknown as BoardApi;
- const icons = openItemMenu(api)
- .map(item => (item && "uiIcon" in item ? item.uiIcon : undefined));
+ const items = openItemMenu(api);
+ const icons = items.map(item => (item && "uiIcon" in item ? item.uiIcon : undefined));
expect(icons).not.toContain("bx bx-list-plus");
expect(icons).not.toContain("bx bx-vertical-top");
// What the menu still offers, so the gate is about the places alone.
expect(icons).toContain("bx bx-rename");
expect(icons).toContain("bx bx-outline");
+
+ // The divider goes with them: the heading below already breaks the menu there.
+ const at = items.findIndex(item => item && "uiIcon" in item
+ && item.uiIcon === "bx bx-rename");
+ expect(items[at + 1]).toMatchObject({ kind: "header" });
});
it("copies a card into the board, after the one it was made from", async () => {
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index 918b724750..71b74d9a9f 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -449,8 +449,34 @@ export function openNoteContextMenu(
event.preventDefault();
event.stopPropagation();
- // A sorted column decides where its cards go, so nothing that names a place is offered.
- const isSorted = api.isColumnSorted(column);
+ // Where a card goes among the others, which a sorted column decides for itself. Kept in a
+ // group of its own only while it holds something, or the menu shows a stray divider.
+ const placement: MenuItem<CommandNames>[] = api.isColumnSorted(column) ? [] : [
+ {
+ title: t("board_view.insert-above"),
+ uiIcon: "bx bx-list-plus",
+ shortcut: "Shift+Enter",
+ handler: () => onInsert(index)
+ },
+ {
+ title: t("board_view.insert-below"),
+ uiIcon: "bx bx-empty",
+ shortcut: "Enter",
+ handler: () => onInsert(index + 1)
+ },
+ // Left out for the card already at the head, which has nowhere to go.
+ ...(api.isFirstInColumn(branchId, column) ? [] : [ {
+ title: t("board_view.move-to-top"),
+ uiIcon: "bx bx-vertical-top",
+ shortcut: "Ctrl+Home",
+ handler: () => {
+ // Asked for before the write: the card is blurred as it is moved in the page, and
+ // the reveal that follows the focus is what shows where it went.
+ onFocusCard(note.noteId);
+ api.moveToColumnStart(note.noteId, branchId, column);
+ }
+ } ])
+ ];
contextMenu.show({
x: event.pageX,
@@ -463,33 +489,9 @@ export function openNoteContextMenu(
shortcut: "F2",
handler: () => api.startEditing(branchId)
},
- { kind: "separator" },
- ...(isSorted ? [] : [
- {
- title: t("board_view.insert-above"),
- uiIcon: "bx bx-list-plus",
- shortcut: "Shift+Enter",
- handler: () => onInsert(index)
- },
- {
- title: t("board_view.insert-below"),
- uiIcon: "bx bx-empty",
- shortcut: "Enter",
- handler: () => onInsert(index + 1)
- }
- ]),
- // Left out for the card already at the head, which has nowhere to go.
- ...(isSorted || api.isFirstInColumn(branchId, column) ? [] : [ {
- title: t("board_view.move-to-top"),
- uiIcon: "bx bx-vertical-top",
- shortcut: "Ctrl+Home",
- handler: () => {
- // Asked for before the write: the card is blurred as it is moved in the page,
- // and the reveal that follows the focus is what shows where it went.
- onFocusCard(note.noteId);
- api.moveToColumnStart(note.noteId, branchId, column);
- }
- } ]),
+ ...(placement.length
+ ? [ { kind: "separator" } as MenuItem<CommandNames>, ...placement ]
+ : []),
{ kind: "header", title: api.getStatusLabel() },
...buildColumnItems(api, note, column, onFocusCard),
{ kind: "separator" },