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

Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
Jono KemballandJulius Marminge authored and GitHub committed 2026-03-28 23:09:19 +00:00
1 parent 5210a833a5
commit 64d21bd6d2
3 files changed
+78 -4

No files matched your search

@@ -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,
+9
View File
@@ -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;
+36 -4
View File
@@ -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();