Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix some issues

Adorian Doran4990d4e99900
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index 0827c5a64b..bc155a4e4f 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -740,19 +740,23 @@ describe("BoardApi card operations", () => {
});
/**
- * 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.
+ * A card can only be placed against a neighbour that is drawn, so a move leaving the cards on
+ * screen where they are would move the ones a filter hides instead: dropping the second card
+ * drawn back at the end writes `moveAfterBranch` against the first, taking it past the hidden
+ * card between them.
*/
- it("places a card a filter makes look as though it has not moved", async () => {
+ it("moves nothing for a drop that leaves the cards a filter draws where they are", async () => {
const { api, done } = createBoardWithSpareCard((all) => [ all[0], all[2] ]);
- // Before the second card drawn, which stands past the one the filter hides.
+ // Back at the end of the two cards drawn, which is where the second one already stands.
+ await api.moveWithinBoard(
+ [ { noteId: done[2].note.noteId, branchId: done[2].branch.branchId } ], "Done", 2);
+ // And the same drop read from the other card: before the second drawn, where it already is.
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);
+ expect(branches.moveBeforeBranch).not.toHaveBeenCalled();
+ expect(branches.moveAfterBranch).not.toHaveBeenCalled();
});
it("moves nothing for a card dropped where it is, or one it cannot find", async () => {
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 6ff7d69354..69aea6f235 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -1398,20 +1398,18 @@ export default class BoardApi {
// 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.
//
- // 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;
- }
+ // Compared over the cards on screen, which is the order the drop was aimed at. Under a
+ // filter `moveBeforeBranch` can only place a card against a visible neighbour, so writing
+ // a move that leaves the screen unchanged would reorder the hidden cards instead.
+ 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
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.css
index 3010778630..ced0c03204 100644
--- a/apps/client/src/widgets/collections/board/index.css
+++ b/apps/client/src/widgets/collections/board/index.css
@@ -33,8 +33,8 @@
--board-drag-ring-width: 3px;
/* The ring a picked-out card carries. */
--board-selected-ring-color: var(--link-color);
- /* The wash the board goes behind while a card is being named. Light: it is there to draw the
- eye to the field, not to shut the board off. */
+ /* Dims the board while a card is being named. Kept light: it draws the eye to the field rather
+ than hiding what is behind it. */
--board-edit-backdrop: rgba(0, 0, 0, 0.15);
--board-focus-outline-saturation: 55%;
@@ -656,11 +656,11 @@ body.mobile .board-view-container .board-add-column {
padding: 0;
}
-/* The board behind the card being named.
+/* Dims the board while a card is being named.
*
- * A sibling of the scrolling container rather than a child, so it covers the board as it stands
- * rather than as far as it scrolls. Nothing between a card and here opens a stacking context, so
- * the card lifts through it on a `z-index` of its own. */
+ * A sibling of `.board-view-container` rather than a child, so it covers the board at its own size
+ * instead of the scrolled width. Nothing between a card and here opens a stacking context, so the
+ * card rises above it on its own `z-index`. */
.board-view .board-edit-backdrop {
position: absolute;
inset: 0;
@@ -671,9 +671,9 @@ body.mobile .board-view-container .board-add-column {
transition: opacity 0.3s ease;
}
-/* Read off the field itself rather than from the board's state: a new item's field is the column's
- own business, and the one that opens between two cards is a third piece of state again.
- `inserting` is that one alone, so the field at the foot of a column raises nothing. */
+/* Matched on the field rather than on state in `index.tsx`: each column holds its own editing
+ state. `inserting` marks only the field that opens between two cards, so the one at the foot of
+ a column leaves the backdrop down. */
.board-view:has(.board-note.editing, .board-new-item.inserting) .board-edit-backdrop {
opacity: 1;
}
@@ -683,16 +683,15 @@ body.mobile .board-view-container .board-add-column {
z-index: 51;
}
-/* While a title is being typed the board stops answering the pointer: a card neither lights up
- under it nor takes a press, so leaving the field cannot also open a note or pick a card out.
- `:hover` follows hit testing rather than any event, so this is the only thing that takes it away.
- The columns themselves are left alone, which is what keeps the board scrolling, and the field is
- excluded rather than re-enabled below: this rule outweighs a plainer one, and the field would go
- inert with everything else.
+/* Stops the cards receiving the pointer while a title is being typed, so that dismissing the field
+ cannot also open a note or select a card. `:hover` follows hit testing rather than events, so
+ `pointer-events` is the only way to suppress it. `.board-column` itself keeps its events, which
+ is what keeps the board scrolling. The edited field is excluded with `:not(.editing)` rather than
+ re-enabled in a later rule, which this selector would outweigh.
- It restyles every card on the board, which is a few hundred milliseconds on a board of thousands,
- and is why it waits for `frozen` rather than following the wash: done in the same frame the wash
- begins in, that recalculation eats the fade whole. */
+ This restyles every card, a few hundred milliseconds on a board of thousands, so it waits for
+ `frozen` instead of matching the backdrop: applied in the frame the fade starts in, the
+ recalculation drops the fade's frames. */
.board-view.frozen :is(
.board-column > h3,
.board-column > .board-new-item,
@@ -701,6 +700,18 @@ body.mobile .board-view-container .board-add-column {
pointer-events: none;
}
+/* `motion-disabled` sets `transition: none !important` on everything, so `.board-edit-backdrop`
+ fires no `transitionend` and `frozen` is never set. There is no fade to protect either, so the
+ same fields freeze the board as soon as they open. */
+body#trilium-app.motion-disabled
+ .board-view:has(.board-note.editing, .board-new-item.inserting) :is(
+ .board-column > h3,
+ .board-column > .board-new-item,
+ .board-column-content > *:not(.editing)
+) {
+ pointer-events: none;
+}
+
/* The fade a column draws over its edges is a mask, and a mask holds everything under it in a
layer of its own, which the field being typed into could not rise out of. Taken off the one
column that holds it, for as long as it stands. `!important` because `useScrollFade` writes the
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index e742f2dceb..a86cb02054 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -386,7 +386,7 @@ export default function BoardView({
/** Everything a card could be made from: the note types and every template. */
const availableTemplates = useNoteTypeOptions();
const [ isEditingProperties, setIsEditingProperties ] = useState(false);
- /** Whether the board has stopped answering the pointer, which the wash arriving is what sets. */
+ /** Adds `frozen`, which takes `pointer-events` off the cards. Set once the backdrop has faded in. */
const [ isFrozen, setIsFrozen ] = useState(false);
const selectColumn = useCallback<Dispatch<StateUpdater<string | undefined>>>((column) => {
setIsPeekingAll(false);
@@ -1147,12 +1147,12 @@ export default function BoardView({
return (
<div className={clsx("board-view", { frozen: isFrozen })}>
- {/* Stands over the board while a title is being typed, with the field lifted through
- it. Always drawn, so it fades in rather than appearing. Which fields raise it is
- the stylesheet's to say, since each keeps its own state.
+ {/* Dims the board while a title is being typed, with the edited card lifted above it.
+ Always rendered so that it can fade in. `index.css` picks the fields that raise it
+ with `:has()`, since each column holds its own editing state.
- The board is frozen once the wash has arrived rather than as it starts: freezing
- restyles every card, which in the same frame would eat the fade whole. */}
+ `frozen` waits for the fade to finish: setting it restyles every card, which in the
+ same frame drops the fade's frames. */}
<div
className="board-edit-backdrop"
onTransitionEnd={(e) => setIsFrozen(