Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/web/src/components/Sidebar.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getVisibleThreadsForProject,
getProjectSortTimestamp,
hasUnseenCompletion,
isContextMenuPointerDown,
resolveProjectStatusIndicator,
resolveSidebarNewThreadEnvMode,
resolveThreadRowClassName,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 36 additions & 4 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -93,6 +101,7 @@ import { useThreadSelectionStore } from "../threadSelectionStore";
import { isNonEmpty as isNonEmptyString } from "effect/String";
import {
getVisibleThreadsForProject,
isContextMenuPointerDown,
resolveProjectStatusIndicator,
resolveSidebarNewThreadEnvMode,
resolveThreadRowClassName,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
Loading