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: keep a set of cards selected after dropping
Adorian Doran5593b1cfa64d
diff --git a/apps/client/src/widgets/collections/board/board_drag.spec.tsx b/apps/client/src/widgets/collections/board/board_drag.spec.tsxindex 5564af2c79..b6b642132a 100644--- a/apps/client/src/widgets/collections/board/board_drag.spec.tsx+++ b/apps/client/src/widgets/collections/board/board_drag.spec.tsx@@ -66,6 +66,32 @@ describe("useBoardDrag, carrying a card", () => {expect(copy?.querySelector(".title")).toBeNull();});+ /**+ * A mouse drag is followed by a click on whatever the press and the release have in common,+ * which for a card carried anywhere is the board itself. Left to stand, letting a card go+ * would also read as a click on the board, which is a gesture of its own.+ */+ it("takes the click a mouse drag is followed by", () => {+ setup();+ const reached = vi.fn();+ board.addEventListener("click", reached);++ press(card("n1"), 50, 60);+ move(90, 90);+ release(90, 90);++ const click = new MouseEvent("click", { bubbles: true, cancelable: true });+ card("n2").dispatchEvent(click);++ expect(reached).not.toHaveBeenCalled();+ expect(click.defaultPrevented).toBe(true);++ // The one click, and no more: a press of the reader's own still counts.+ const later = new MouseEvent("click", { bubbles: true, cancelable: true });+ card("n2").dispatchEvent(later);+ expect(reached).toHaveBeenCalledTimes(1);+ });+/** Two cards on the move leave one card behind the copy. */it("stacks one card behind a pair", () => {setup({ carried: [ "n1", "n2" ] });diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.tsindex bc96471978..71f3cc69c0 100644--- a/apps/client/src/widgets/collections/board/board_drag.ts+++ b/apps/client/src/widgets/collections/board/board_drag.ts@@ -357,6 +357,7 @@ export function useBoardDrag(const tapped = held.touch && !held.active && event.type === "pointerup"&& Math.hypot(event.clientX - held.startX, event.clientY - held.startY)<= TOUCH_TOLERANCE;+ const dragged = held.active && event.type === "pointerup";const target = held.menuTarget;// A tap on a collapsed column opens it: that is what the strip is for, and its menu is// on the button it carries. Everything else answers a tap with its menu, the long@@ -371,14 +372,29 @@ export function useBoardDrag(// first of them takes the menu straight back off again. Refused at `touchend`,// which is what the browser makes them from, and which has yet to be sent.justTapped = true;- // The click is left out as well, for a browser that sends one regardless. Given up- // after a moment so a later click of the reader's own is never the one taken.- container.addEventListener("click", swallow, { capture: true, once: true });- window.setTimeout(- () => container.removeEventListener("click", swallow, { capture: true }),- COMPATIBILITY_WINDOW_MS);+ // The click is left out as well, for a browser that sends one regardless.+ swallowNextClick();askForMenu(target, event.clientX, event.clientY);}++ // A mouse drag is followed by a click on whatever the press and the release have in+ // common, which for a card carried anywhere is the board itself. Taken here, so that+ // what a click on the board means is not also what letting go of a card means.+ if (dragged) {+ swallowNextClick();+ }+ };++ /**+ * Refuses the one click the browser is about to send, if it sends one.+ *+ * Given up after a moment so a later click of the reader's own is never the one taken.+ */+ const swallowNextClick = () => {+ container.addEventListener("click", swallow, { capture: true, once: true });+ window.setTimeout(+ () => container.removeEventListener("click", swallow, { capture: true }),+ COMPATIBILITY_WINDOW_MS);};/** Set between a tap and the `touchend` the browser would make mouse events from. */