The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 07:30 UTC
fix: Prevent sidebar project dragging when using macos control+click to open context menu (#873)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Jono Kemball committed
Mar 29, 2026 at 12:09 UTC
64d21bd6d29fbf795262fd6f031db81e3ddbad02
3 files changed
+78
-4
apps/web/src/components/Sidebar.logic.test.ts
+33
@@ -5,6 +5,7 @@ import {
5
getVisibleThreadsForProject,
6
getProjectSortTimestamp,
7
hasUnseenCompletion,
8
+ isContextMenuPointerDown,
9
resolveProjectStatusIndicator,
10
resolveSidebarNewThreadEnvMode,
11
resolveThreadRowClassName,
@@ -96,6 +97,38 @@ describe("resolveSidebarNewThreadEnvMode", () => {
97
});
98
});
99
100
+describe("isContextMenuPointerDown", () => {
101
+ it("treats secondary-button presses as context menu gestures on all platforms", () => {
102
+ expect(
103
+ isContextMenuPointerDown({
104
+ button: 2,
105
+ ctrlKey: false,
106
+ isMac: false,
107
+ }),
108
+ ).toBe(true);
109
+ });
110
+
111
+ it("treats ctrl+primary-click as a context menu gesture on macOS", () => {
112
+ expect(
113
+ isContextMenuPointerDown({
114
+ button: 0,
115
+ ctrlKey: true,
116
+ isMac: true,
117
+ }),
118
+ ).toBe(true);
119
+ });
120
+
121
+ it("does not treat ctrl+primary-click as a context menu gesture off macOS", () => {
122
+ expect(
123
+ isContextMenuPointerDown({
124
+ button: 0,
125
+ ctrlKey: true,
126
+ isMac: false,
127
+ }),
128
+ ).toBe(false);
129
+ });
130
+});
131
+
132
describe("resolveThreadStatusPill", () => {
133
const baseThread = {
134
interactionMode: "plan" as const,
apps/web/src/components/Sidebar.logic.ts
+9
@@ -67,6 +67,15 @@ export function resolveSidebarNewThreadEnvMode(input: {
67
return input.requestedEnvMode ?? input.defaultEnvMode;
68
}
69
70
+export function isContextMenuPointerDown(input: {
71
+ button: number;
72
+ ctrlKey: boolean;
73
+ isMac: boolean;
74
+}): boolean {
75
+ if (input.button === 2) return true;
76
+ return input.isMac && input.button === 0 && input.ctrlKey;
77
+}
78
+
79
export function resolveThreadRowClassName(input: {
80
isActive: boolean;
81
isSelected: boolean;
apps/web/src/components/Sidebar.tsx
+36
-4
@@ -13,7 +13,15 @@ import {
13
} from "lucide-react";
14
import { ProjectFavicon } from "./ProjectFavicon";
15
import { autoAnimate } from "@formkit/auto-animate";
16
-import { useCallback, useEffect, useMemo, useRef, useState, type MouseEvent } from "react";
16
+import {
17
+ useCallback,
18
+ useEffect,
19
+ useMemo,
20
+ useRef,
21
+ useState,
22
+ type MouseEvent,
23
+ type PointerEvent,
24
+} from "react";
25
import {
26
DndContext,
27
type DragCancelEvent,
@@ -93,6 +101,7 @@ import { useThreadSelectionStore } from "../threadSelectionStore";
101
import { isNonEmpty as isNonEmptyString } from "effect/String";
102
import {
103
getVisibleThreadsForProject,
104
+ isContextMenuPointerDown,
105
resolveProjectStatusIndicator,
106
resolveSidebarNewThreadEnvMode,
107
resolveThreadRowClassName,
@@ -348,6 +357,7 @@ export default function Sidebar() {
357
const renamingInputRef = useRef<HTMLInputElement | null>(null);
358
const dragInProgressRef = useRef(false);
359
const suppressProjectClickAfterDragRef = useRef(false);
360
+ const suppressProjectClickForContextMenuRef = useRef(false);
361
const [desktopUpdateState, setDesktopUpdateState] = useState<DesktopUpdateState | null>(null);
362
const selectedThreadIds = useThreadSelectionStore((s) => s.selectedThreadIds);
363
const toggleThreadSelection = useThreadSelectionStore((s) => s.toggleThread);
@@ -941,9 +951,24 @@ export default function Sidebar() {
951
animatedThreadListsRef.current.add(node);
952
}, []);
953
944
- const handleProjectTitlePointerDownCapture = useCallback(() => {
945
- suppressProjectClickAfterDragRef.current = false;
946
- }, []);
954
+ const handleProjectTitlePointerDownCapture = useCallback(
955
+ (event: PointerEvent<HTMLButtonElement>) => {
956
+ suppressProjectClickForContextMenuRef.current = false;
957
+ if (
958
+ isContextMenuPointerDown({
959
+ button: event.button,
960
+ ctrlKey: event.ctrlKey,
961
+ isMac: isMacPlatform(navigator.platform),
962
+ })
963
+ ) {
964
+ // Keep context-menu gestures from arming the sortable drag sensor.
965
+ event.stopPropagation();
966
+ }
967
+
968
+ suppressProjectClickAfterDragRef.current = false;
969
+ },
970
+ [],
971
+ );
972
973
const visibleThreads = useMemo(
974
() => threads.filter((thread) => thread.archivedAt === null),
@@ -1242,6 +1267,7 @@ export default function Sidebar() {
1267
onKeyDown={(event) => handleProjectTitleKeyDown(event, project.id)}
1268
onContextMenu={(event) => {
1269
event.preventDefault();
1270
+ suppressProjectClickForContextMenuRef.current = true;
1271
void handleProjectContextMenu(project.id, {
1272
x: event.clientX,
1273
y: event.clientY,
@@ -1351,6 +1377,12 @@ export default function Sidebar() {
1377
1378
const handleProjectTitleClick = useCallback(
1379
(event: React.MouseEvent<HTMLButtonElement>, projectId: ProjectId) => {
1380
+ if (suppressProjectClickForContextMenuRef.current) {
1381
+ suppressProjectClickForContextMenuRef.current = false;
1382
+ event.preventDefault();
1383
+ event.stopPropagation();
1384
+ return;
1385
+ }
1386
if (dragInProgressRef.current) {
1387
event.preventDefault();
1388
event.stopPropagation();