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/collections/board: fix an issue
Adorian Doranc1dc473af178
diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.tsindex b7ead0ac70..1bb6dce030 100644--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts@@ -950,7 +950,8 @@ describe("Board item context menu", () => {* run of cards off does not carry the reader to wherever each one landed.*/it("focuses the card taking its place rather than the one it files", () => {- const cards = [ 0, 1, 2, 3 ].map(() => buildNote({ title: "Card" }) as FNote);+ // Five, since a shorter column lands on the same card either way and hides a miscount.+ const cards = [ 0, 1, 2, 3, 4 ].map(() => buildNote({ title: "Card" }) as FNote);const ids = cards.map(card => card.noteId);const api = {columns: [ "To Do", "Done" ],@@ -961,11 +962,14 @@ describe("Board item context menu", () => {changeColumn: vi.fn(async () => {})} as unknown as BoardApi;- /** Files the card standing at `index` under "Done", and says what was focused after. */- const fileFrom = (index: number) => {+ /**+ * Files the cards at `filed` under "Done", from the menu opened on the first of them,+ * and says what was focused after.+ */+ const fileFrom = (...filed: number[]) => {const focusCard = vi.fn();- const items = openItemMenu(- api, "To Do", focusCard, vi.fn(), index, vi.fn(), [ cards[index] ]);+ const items = openItemMenu(api, "To Do", focusCard, vi.fn(), filed[0], vi.fn(),+ filed.map(at => cards[at]));const header = items.findIndex(item => item && "kind" in item && item.kind === "header");const done = items[header + 2];if (done && "handler" in done) done.handler?.(done, {} as never);@@ -975,7 +979,13 @@ describe("Board item context menu", () => {// The card that closes the gap is the one after it.expect(fileFrom(1)).toEqual([ ids[2] ]);// From the foot there is none after it, so the column's new last card takes the focus.- expect(fileFrom(3)).toEqual([ ids[2] ]);+ expect(fileFrom(4)).toEqual([ ids[3] ]);+ // A selection leaves the first card still standing below the one the menu was opened on.+ expect(fileFrom(1, 3)).toEqual([ ids[2] ]);+ // And the cards leaving from above it are counted out of its place first.+ expect(fileFrom(2, 0)).toEqual([ ids[3] ]);+ // With every card filed there is none left to take.+ expect(fileFrom(0, 1, 2, 3, 4)).toEqual([]);});/** The card it is already under writes nothing, so there is no reason to move the focus. */diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.tsindex 0d5bf07471..12a76e3721 100644--- a/apps/client/src/widgets/collections/board/context_menu.ts+++ b/apps/client/src/widgets/collections/board/context_menu.ts@@ -447,9 +447,13 @@ function buildColumnItems(api: Api, target: NoteMenuTarget): MenuItem<CommandNam// wherever each one landed. Asked for before the write, which draws the board again.if (name !== current) {const going = new Set(target.notes.map((note) => note.noteId));- const staying = api.getColumnNoteIds(target.column)- .filter((noteId) => !going.has(noteId));- const next = staying[target.index] ?? staying.at(-1);+ const noteIds = api.getColumnNoteIds(target.column);+ const staying = noteIds.filter((noteId) => !going.has(noteId));+ // Counted among the cards that stay: any leaving from above this one close up+ // first, so its place among them is that much higher than the place it held.+ const above = noteIds.slice(0, target.index)+ .filter((noteId) => going.has(noteId)).length;+ const next = staying[target.index - above] ?? staying.at(-1);if (next) {target.onFocusCard(next);}