Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(society): dragging the island pans it again instead of selecting the signs

rubenluetke10-beep516caa319b79
diff --git a/jarvis/ui/web/frontend/src/components/society/world/useWorldControls.test.tsx b/jarvis/ui/web/frontend/src/components/society/world/useWorldControls.test.tsx
new file mode 100644
index 0000000000..b6fa12f0a7
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/world/useWorldControls.test.tsx
@@ -0,0 +1,69 @@
+/**
+ * Dragging the island must never paint its signs blue.
+ *
+ * The labels over the houses and the HUD are DOM on top of the canvas, so a
+ * held left button used to start a text selection across them — which also
+ * made the browser cancel the pointer stream and drop the pan halfway. The
+ * guard below is the contract: while the button is down nothing may start a
+ * selection, and the moment it is released the page is readable again.
+ */
+import { useRef } from "react";
+import { cleanup, render } from "@testing-library/react";
+import { afterEach, describe, expect, it } from "vitest";
+
+import { useWorldControls } from "./useWorldControls";
+
+function Stage() {
+ const ref = useRef<HTMLDivElement>(null);
+ useWorldControls(ref, true);
+ return <div ref={ref} data-testid="stage" tabIndex={0} />;
+}
+
+/** jsdom ships no PointerEvent; the hook only reads `button` and `pointerId`. */
+function pointer(type: string): Event {
+ return new MouseEvent(type, { button: 0, bubbles: true, cancelable: true });
+}
+
+/** Did a selection get to start? */
+function selectionStarts(): boolean {
+ const event = new Event("selectstart", { bubbles: true, cancelable: true });
+ document.dispatchEvent(event);
+ return !event.defaultPrevented;
+}
+
+afterEach(cleanup);
+
+describe("useWorldControls", () => {
+ it("blocks text selection while the left button is held, and only then", () => {
+ const { getByTestId } = render(<Stage />);
+ const host = getByTestId("stage");
+
+ expect(selectionStarts()).toBe(true);
+
+ host.dispatchEvent(pointer("pointerdown"));
+ expect(selectionStarts()).toBe(false);
+
+ host.dispatchEvent(pointer("pointerup"));
+ expect(selectionStarts()).toBe(true);
+ });
+
+ it("releases the guard when a drag is cancelled, not only on a clean release", () => {
+ const { getByTestId } = render(<Stage />);
+ const host = getByTestId("stage");
+
+ host.dispatchEvent(pointer("pointerdown"));
+ expect(selectionStarts()).toBe(false);
+
+ host.dispatchEvent(pointer("pointercancel"));
+ expect(selectionStarts()).toBe(true);
+ });
+
+ it("leaves the page selectable after the stage unmounts mid-drag", () => {
+ const { getByTestId, unmount } = render(<Stage />);
+ getByTestId("stage").dispatchEvent(pointer("pointerdown"));
+
+ unmount();
+
+ expect(selectionStarts()).toBe(true);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/world/useWorldControls.ts b/jarvis/ui/web/frontend/src/components/society/world/useWorldControls.ts
index 8c6297ad21..b6fb0da9c3 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/useWorldControls.ts
+++ b/jarvis/ui/web/frontend/src/components/society/world/useWorldControls.ts
@@ -28,12 +28,30 @@ export function useWorldControls(hostRef: RefObject<HTMLElement | null>, enabled
let travelled = 0;
let lastWheel = 0;
+ /*
+ * A held left button over the island pans it, so nothing may start a text
+ * selection while that button is down. The signs over the houses and the
+ * HUD are DOM drawn on top of the canvas: as the pointer travels the
+ * browser paints them blue, and — worse — a selection that starts under a
+ * captured pointer makes Chromium fire `pointercancel`, which ends the pan
+ * halfway through the drag. `user-select: none` on the stage does not
+ * settle it either, because the selection can begin over the HUD, which
+ * sits outside the stage and stays readable by design.
+ *
+ * Blocking `selectstart` for exactly as long as the button is held costs
+ * nothing (there is nothing to read on the map) and leaves every other
+ * surface of the app selectable.
+ */
+ const blockSelectStart = (e: Event) => e.preventDefault();
+ const allowSelectStart = () => document.removeEventListener("selectstart", blockSelectStart);
+
const onPointerDown = (e: PointerEvent) => {
if (e.button !== 0) return;
pointerId = e.pointerId;
lastX = e.clientX;
lastY = e.clientY;
travelled = 0;
+ document.addEventListener("selectstart", blockSelectStart);
host.focus({ preventScroll: true });
};
@@ -61,6 +79,7 @@ export function useWorldControls(hostRef: RefObject<HTMLElement | null>, enabled
const endDrag = (e: PointerEvent) => {
if (pointerId !== e.pointerId) return;
pointerId = null;
+ allowSelectStart();
if (store.getState().dragging) {
// Let the click that ends a drag pass first, then re-enable figure clicks.
window.setTimeout(() => store.getState().setDragging(false), 0);
@@ -107,6 +126,7 @@ export function useWorldControls(hostRef: RefObject<HTMLElement | null>, enabled
host.removeEventListener("keydown", onKeyDown);
host.removeEventListener("keyup", onKeyUp);
host.removeEventListener("blur", onBlur);
+ allowSelectStart();
store.getState().clearKeys();
store.getState().setDragging(false);
};
diff --git a/jarvis/ui/web/frontend/src/components/society/world/world.css b/jarvis/ui/web/frontend/src/components/society/world/world.css
index 7feed71c1a..b838ae0f60 100644
--- a/jarvis/ui/web/frontend/src/components/society/world/world.css
+++ b/jarvis/ui/web/frontend/src/components/society/world/world.css
@@ -102,6 +102,8 @@
justify-content: space-between;
padding: 12px;
pointer-events: none;
+ /* Chrome to press, never text to read: a pan dragged across it must not paint it blue. */
+ user-select: none;
font-family: "Pixelify Sans", "Inter Variable", "Inter", ui-sans-serif, system-ui, sans-serif;
}
.sw-hud > * > * {