Skip to content

Build your personal knowledge base with Trilium Notes

client: fix some issues

Adorian Doran5c140e1c14c1
diff --git a/apps/client/src/services/note_set.ts b/apps/client/src/services/note_set.ts
index f8316cf693..0ff934a4fe 100644
--- a/apps/client/src/services/note_set.ts
+++ b/apps/client/src/services/note_set.ts
@@ -32,8 +32,8 @@ export function shared<T>(notes: FNote[], read: (note: FNote) => T): Shared<T> {
* Written through `setLabelValues`, which reuses the labels already there and leaves inherited ones
* alone. The bulk-action endpoint would be one request instead of several, but its
* `updateLabelValue` only touches labels a note already owns and `addLabel` always adds another,
- * so neither writes "hold this value" on a note that may or may not already hold it. The notes go
- * together instead, so a set is not written one card at a time.
+ * so neither says "hold this value" for a note that might already hold it. The notes go together
+ * instead, so a set is not written one card at a time.
*/
export async function setLabelOnNotes(notes: FNote[], name: string, value: string) {
await Promise.all(notes.map((note) => setLabelValues(note, name, [ value ])));
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index 5c6d47b019..0827c5a64b 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -739,6 +739,22 @@ describe("BoardApi card operations", () => {
.toHaveBeenLastCalledWith([ second.branch.branchId ], third.branch.branchId);
});
+ /**
+ * The place a card is dropped at is counted among the cards on screen, so a filter can leave
+ * that order unchanged for a move that does reorder the column underneath. Read as standing
+ * still, the move would be dropped and the board would snap back.
+ */
+ it("places a card a filter makes look as though it has not moved", async () => {
+ const { api, done } = createBoardWithSpareCard((all) => [ all[0], all[2] ]);
+
+ // Before the second card drawn, which stands past the one the filter hides.
+ await api.moveWithinBoard(
+ [ { noteId: done[0].note.noteId, branchId: done[0].branch.branchId } ], "Done", 1);
+
+ expect(branches.moveBeforeBranch)
+ .toHaveBeenCalledWith([ done[0].branch.branchId ], done[2].branch.branchId);
+ });
+
it("moves nothing for a card dropped where it is, or one it cannot find", async () => {
const { api, items } = createBoardWithCards();
const [ first ] = items;
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 40c27189fd..6ff7d69354 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -1390,23 +1390,34 @@ export default class BoardApi {
const staying = targetItems.filter((item) => !moved.has(item.branch.branchId));
const at = targetIndex - above;
+ // The column as the board holds it, cards a filter hides included, which is what says
+ // whether a card is arriving from elsewhere and whether this move changes anything.
+ const whole = this.allByColumn?.get(targetColumn) ?? targetItems;
+ const held = whole.map((item) => item.branch.branchId);
+
// Nothing at all is written where the cards already stand where this would put them, which
// is what a card dropped back where it was picked up amounts to.
- const standing = targetItems.map((item) => item.branch.branchId);
- const landing = [
- ...staying.slice(0, at).map((item) => item.branch.branchId),
- ...branchIds,
- ...staying.slice(at).map((item) => item.branch.branchId)
- ];
- if (landing.length === standing.length
- && landing.every((branchId, place) => branchId === standing[place])) {
- return;
+ //
+ // Only where the column is drawn whole. The places are counted among the cards on screen,
+ // so a filter hiding some of them leaves that order unchanged for a move that does reorder
+ // what is underneath, and the move would be dropped for standing still.
+ if (whole.length === targetItems.length) {
+ const standing = targetItems.map((item) => item.branch.branchId);
+ const landing = [
+ ...staying.slice(0, at).map((item) => item.branch.branchId),
+ ...branchIds,
+ ...staying.slice(at).map((item) => item.branch.branchId)
+ ];
+ if (landing.length === standing.length
+ && landing.every((branchId, place) => branchId === standing[place])) {
+ return;
+ }
}
// Only the cards arriving from elsewhere are written: one already under this column holds
// the value already, and writing it again is a change the board has to redraw for.
// Together rather than one after another, so a set does not arrive a card at a time.
- const arriving = moving.filter((card) => !standing.includes(card.branchId));
+ const arriving = moving.filter((card) => !held.includes(card.branchId));
if (arriving.length) {
await Promise.all(arriving.map((card) => this.changeColumn(card.noteId, targetColumn)));
}
diff --git a/apps/client/src/widgets/collections/board/keyboard.spec.tsx b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
index 11b2d96b29..546c90db5a 100644
--- a/apps/client/src/widgets/collections/board/keyboard.spec.tsx
+++ b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
@@ -350,7 +350,7 @@ describe("Board keyboard", () => {
});
/**
- * The card beside the focused one may be leaving with it, so focus walks past the cards on
+ * The card beside the focused one can be leaving with it, so focus walks past the cards on
* their way out rather than landing on one about to be drawn no more.
*/
it("hands focus past the cards going with it", async () => {
diff --git a/apps/client/src/widgets/collections/board/keyboard.ts b/apps/client/src/widgets/collections/board/keyboard.ts
index 4d2a3cca2c..5c831f03f0 100644
--- a/apps/client/src/widgets/collections/board/keyboard.ts
+++ b/apps/client/src/widgets/collections/board/keyboard.ts
@@ -350,7 +350,7 @@ export function useBoardKeyboard({
* What to put focus on once a card goes: the one under it, the one over it, or the column.
*
* @param going the cards leaving with it, which are passed over: a whole selection can be deleted
- * at once, and the card beside the focused one may be on its way out too.
+ * at once, and the card beside the focused one can be on its way out too.
*/
function neighbourOf(
container: HTMLElement,