Skip to content
Open
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
30 changes: 30 additions & 0 deletions apps/web/src/components/Sidebar.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";

import {
hasUnseenCompletion,
isContextMenuPointerDown,
resolveThreadStatusPill,
shouldClearThreadSelectionOnMouseDown,
} from "./Sidebar.logic";
Expand Down Expand Up @@ -62,6 +63,35 @@ describe("shouldClearThreadSelectionOnMouseDown", () => {
});
});

describe("isContextMenuPointerDown", () => {
it("treats secondary-button pointerdown as a context-menu gesture", () => {
expect(
isContextMenuPointerDown({
button: 2,
ctrlKey: false,
}),
).toBe(true);
});

it("treats ctrl-primary-click as a context-menu gesture", () => {
expect(
isContextMenuPointerDown({
button: 0,
ctrlKey: true,
}),
).toBe(true);
});

it("does not treat primary-button pointerdown as a context-menu gesture", () => {
expect(
isContextMenuPointerDown({
button: 0,
ctrlKey: false,
}),
).toBe(false);
});
});

describe("resolveThreadStatusPill", () => {
const baseThread = {
interactionMode: "plan" as const,
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export function shouldClearThreadSelectionOnMouseDown(target: HTMLElement | null
return !target.closest(THREAD_SELECTION_SAFE_SELECTOR);
}

export function isContextMenuPointerDown(input: { button: number; ctrlKey: boolean }): boolean {
if (input.button === 2) return true;
return input.button === 0 && input.ctrlKey;
}

export function resolveThreadStatusPill(input: {
thread: ThreadStatusInput;
hasPendingApprovals: boolean;
Expand Down
44 changes: 39 additions & 5 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import {
TerminalIcon,
TriangleAlertIcon,
} from "lucide-react";
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 @@ -83,7 +91,11 @@ import {
import { useThreadSelectionStore } from "../threadSelectionStore";
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
import { isNonEmpty as isNonEmptyString } from "effect/String";
import { resolveThreadStatusPill, shouldClearThreadSelectionOnMouseDown } from "./Sidebar.logic";
import {
isContextMenuPointerDown,
resolveThreadStatusPill,
shouldClearThreadSelectionOnMouseDown,
} from "./Sidebar.logic";

const EMPTY_KEYBINDINGS: ResolvedKeybindingsConfig = [];
const THREAD_PREVIEW_LIMIT = 6;
Expand Down Expand Up @@ -301,6 +313,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 @@ -998,12 +1011,32 @@ export default function Sidebar() {
dragInProgressRef.current = false;
}, []);

const handleProjectTitlePointerDownCapture = useCallback(() => {
suppressProjectClickAfterDragRef.current = false;
}, []);
const handleProjectTitlePointerDownCapture = useCallback(
(event: PointerEvent<HTMLButtonElement>) => {
suppressProjectClickForContextMenuRef.current = false;
if (
isContextMenuPointerDown({
button: event.button,
ctrlKey: event.ctrlKey,
})
) {
// Keep context-menu gestures from arming the sortable drag sensor.
event.stopPropagation();
}

suppressProjectClickAfterDragRef.current = false;
},
[],
);

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 Expand Up @@ -1453,6 +1486,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