Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix: Prevent sidebar project dragging when using macos control+click to open context menu (#873)

Jono Kemball64d21bd6d29f
diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.ts
index 0824758ba..cc49a82e6 100644
--- a/apps/web/src/components/Sidebar.logic.test.ts
+++ b/apps/web/src/components/Sidebar.logic.test.ts
@@ -5,6 +5,7 @@ import {
getVisibleThreadsForProject,
getProjectSortTimestamp,
hasUnseenCompletion,
+ isContextMenuPointerDown,
resolveProjectStatusIndicator,
resolveSidebarNewThreadEnvMode,
resolveThreadRowClassName,
@@ -96,6 +97,38 @@ describe("resolveSidebarNewThreadEnvMode", () => {
});
});
+describe("isContextMenuPointerDown", () => {
+ it("treats secondary-button presses as context menu gestures on all platforms", () => {
+ expect(
+ isContextMenuPointerDown({
+ button: 2,
+ ctrlKey: false,
+ isMac: false,
+ }),
+ ).toBe(true);
+ });
+
+ it("treats ctrl+primary-click as a context menu gesture on macOS", () => {
+ expect(
+ isContextMenuPointerDown({
+ button: 0,
+ ctrlKey: true,
+ isMac: true,
+ }),
+ ).toBe(true);
+ });
+
+ it("does not treat ctrl+primary-click as a context menu gesture off macOS", () => {
+ expect(
+ isContextMenuPointerDown({
+ button: 0,
+ ctrlKey: true,
+ isMac: false,
+ }),
+ ).toBe(false);
+ });
+});
+
describe("resolveThreadStatusPill", () => {
const baseThread = {
interactionMode: "plan" as const,
diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts
index 6ca29d27e..22a6268ac 100644
--- a/apps/web/src/components/Sidebar.logic.ts
+++ b/apps/web/src/components/Sidebar.logic.ts
@@ -67,6 +67,15 @@ export function resolveSidebarNewThreadEnvMode(input: {
return input.requestedEnvMode ?? input.defaultEnvMode;
}
+export function isContextMenuPointerDown(input: {
+ button: number;
+ ctrlKey: boolean;
+ isMac: boolean;
+}): boolean {
+ if (input.button === 2) return true;
+ return input.isMac && input.button === 0 && input.ctrlKey;
+}
+
export function resolveThreadRowClassName(input: {
isActive: boolean;
isSelected: boolean;
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index 299948c86..d6ef9fc81 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -13,7 +13,15 @@ import {
} from "lucide-react";
import { ProjectFavicon } from "./ProjectFavicon";
import { autoAnimate } from "@formkit/auto-animate";
-import { useCallback, useEffect, useMemo, useRef, useState, type MouseEvent } from "react";
+import {
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+ type MouseEvent,
+ type PointerEvent,
+} from "react";
import {
DndContext,
type DragCancelEvent,
@@ -93,6 +101,7 @@ import { useThreadSelectionStore } from "../threadSelectionStore";
import { isNonEmpty as isNonEmptyString } from "effect/String";
import {
getVisibleThreadsForProject,
+ isContextMenuPointerDown,
resolveProjectStatusIndicator,
resolveSidebarNewThreadEnvMode,
resolveThreadRowClassName,
@@ -348,6 +357,7 @@ export default function Sidebar() {
const renamingInputRef = useRef<HTMLInputElement | null>(null);
const dragInProgressRef = useRef(false);
const suppressProjectClickAfterDragRef = useRef(false);
+ const suppressProjectClickForContextMenuRef = useRef(false);
const [desktopUpdateState, setDesktopUpdateState] = useState<DesktopUpdateState | null>(null);
const selectedThreadIds = useThreadSelectionStore((s) => s.selectedThreadIds);
const toggleThreadSelection = useThreadSelectionStore((s) => s.toggleThread);
@@ -941,9 +951,24 @@ export default function Sidebar() {
animatedThreadListsRef.current.add(node);
}, []);
- const handleProjectTitlePointerDownCapture = useCallback(() => {
- suppressProjectClickAfterDragRef.current = false;
- }, []);
+ const handleProjectTitlePointerDownCapture = useCallback(
+ (event: PointerEvent<HTMLButtonElement>) => {
+ suppressProjectClickForContextMenuRef.current = false;
+ if (
+ isContextMenuPointerDown({
+ button: event.button,
+ ctrlKey: event.ctrlKey,
+ isMac: isMacPlatform(navigator.platform),
+ })
+ ) {
+ // Keep context-menu gestures from arming the sortable drag sensor.
+ event.stopPropagation();
+ }
+
+ suppressProjectClickAfterDragRef.current = false;
+ },
+ [],
+ );
const visibleThreads = useMemo(
() => threads.filter((thread) => thread.archivedAt === null),
@@ -1242,6 +1267,7 @@ export default function Sidebar() {
onKeyDown={(event) => handleProjectTitleKeyDown(event, project.id)}
onContextMenu={(event) => {
event.preventDefault();
+ suppressProjectClickForContextMenuRef.current = true;
void handleProjectContextMenu(project.id, {
x: event.clientX,
y: event.clientY,
@@ -1351,6 +1377,12 @@ export default function Sidebar() {
const handleProjectTitleClick = useCallback(
(event: React.MouseEvent<HTMLButtonElement>, projectId: ProjectId) => {
+ if (suppressProjectClickForContextMenuRef.current) {
+ suppressProjectClickForContextMenuRef.current = false;
+ event.preventDefault();
+ event.stopPropagation();
+ return;
+ }
if (dragInProgressRef.current) {
event.preventDefault();
event.stopPropagation();