Skip to content

Commit 9f979db

Browse files
authored
Merge branch 'main' into feat/web/sidebar-v2-copy-thread-id
2 parents fb2b456 + 752acbf commit 9f979db

3 files changed

Lines changed: 74 additions & 20 deletions

File tree

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
sortThreadsForSidebar,
3333
sortProjectsForSidebar,
3434
sortScopedProjectsForSidebar,
35+
shouldCreateNewThreadInCurrentProject,
3536
THREAD_JUMP_HINT_SHOW_DELAY_MS,
3637
} from "./Sidebar.logic";
3738
import {
@@ -410,6 +411,21 @@ describe("isTrailingDoubleClick", () => {
410411
});
411412
});
412413

414+
describe("shouldCreateNewThreadInCurrentProject", () => {
415+
it("creates directly on shift+click in a multi-project setup", () => {
416+
expect(shouldCreateNewThreadInCurrentProject(true, 2)).toBe(true);
417+
});
418+
419+
it("opens the picker on a plain click in a multi-project setup", () => {
420+
expect(shouldCreateNewThreadInCurrentProject(false, 2)).toBe(false);
421+
});
422+
423+
it("creates directly on any click with a single project", () => {
424+
expect(shouldCreateNewThreadInCurrentProject(false, 1)).toBe(true);
425+
expect(shouldCreateNewThreadInCurrentProject(true, 1)).toBe(true);
426+
});
427+
});
428+
413429
describe("orderItemsByPreferredIds", () => {
414430
it("keeps preferred ids first, skips stale ids, and preserves the relative order of remaining items", () => {
415431
const ordered = orderItemsByPreferredIds({

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ export function isTrailingDoubleClick(detail: number): boolean {
274274
return detail > 1;
275275
}
276276

277+
// Shift+click on the new thread button creates directly in the current
278+
// project, skipping the command palette's project picker. With a single
279+
// project there is nothing to pick, so a plain click already creates
280+
// immediately and the modifier changes nothing.
281+
export function shouldCreateNewThreadInCurrentProject(
282+
shiftKey: boolean,
283+
projectGroupCount: number,
284+
): boolean {
285+
return shiftKey || projectGroupCount <= 1;
286+
}
287+
277288
export function orderItemsByPreferredIds<TItem, TId>(input: {
278289
items: readonly TItem[];
279290
preferredIds: readonly TId[];

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ import {
131131
resolveSettledTimestamp,
132132
resolveSidebarThreadStatus,
133133
searchSidebarThreadsByTitle,
134+
shouldCreateNewThreadInCurrentProject,
134135
resolveWorkingStartedAt,
135136
sortLogicalProjectsForSidebar,
136137
sortPinnedThreadsForSidebar,
@@ -3186,29 +3187,39 @@ export default function Sidebar() {
31863187
// falling back to the top project) — same resolution the command palette
31873188
// uses. The command palette already offers a "New thread in..." submenu
31883189
// for multi-project setups.
3189-
const handleNewThreadClick = useCallback(() => {
3190-
// One project: nothing to pick, create immediately.
3191-
if (projectGroups.length <= 1) {
3190+
const handleNewThreadClick = useCallback(
3191+
(event?: ReactMouseEvent) => {
3192+
// One project: nothing to pick, create immediately. Shift+click creates
3193+
// directly in the current project even with several projects, skipping
3194+
// the palette picker.
3195+
if (shouldCreateNewThreadInCurrentProject(event?.shiftKey ?? false, projectGroups.length)) {
3196+
if (isMobile) setOpenMobile(false);
3197+
void startNewThreadFromContext({
3198+
activeDraftThread: newThreadContext.activeDraftThread,
3199+
activeThread: newThreadContext.activeThread ?? undefined,
3200+
defaultProjectRef: newThreadContext.defaultProjectRef,
3201+
handleNewThread: newThreadContext.handleNewThread,
3202+
});
3203+
return;
3204+
}
31923205
if (isMobile) setOpenMobile(false);
3193-
void startNewThreadFromContext({
3194-
activeDraftThread: newThreadContext.activeDraftThread,
3195-
activeThread: newThreadContext.activeThread ?? undefined,
3196-
defaultProjectRef: newThreadContext.defaultProjectRef,
3197-
handleNewThread: newThreadContext.handleNewThread,
3198-
});
3199-
return;
3200-
}
3201-
if (isMobile) setOpenMobile(false);
3202-
openCommandPalette({ open: "new-thread-in" });
3203-
}, [isMobile, newThreadContext, projectGroups.length, setOpenMobile]);
3206+
openCommandPalette({ open: "new-thread-in" });
3207+
},
3208+
[isMobile, newThreadContext, projectGroups.length, setOpenMobile],
3209+
);
32043210

32053211
// The button mirrors chat.new: in multi-project setups both route through
32063212
// the command palette's "New thread in..." picker, and in single-project
3207-
// setups both create immediately. chat.newLocal always creates directly, so
3208-
// it is only a correct label when chat.new is unbound.
3213+
// setups both create immediately. In multi-project setups the label is only
3214+
// the picker's shortcut: falling back to chat.newLocal would advertise the
3215+
// same shortcut for both the picker and direct create. In single-project
3216+
// setups both commands create directly, so chat.newLocal is a valid
3217+
// fallback. The second tooltip line (multi-project only) advertises
3218+
// shift+click and its keyboard twin chat.newLocal for direct create.
32093219
const newThreadShortcutLabel =
32103220
shortcutLabelForCommand(keybindings, "chat.new") ??
3211-
shortcutLabelForCommand(keybindings, "chat.newLocal");
3221+
(projectGroups.length <= 1 ? shortcutLabelForCommand(keybindings, "chat.newLocal") : undefined);
3222+
const newThreadInProjectShortcutLabel = shortcutLabelForCommand(keybindings, "chat.newLocal");
32123223
return (
32133224
<>
32143225
<SidebarChromeHeader isElectron={isElectron} />
@@ -3286,9 +3297,25 @@ export default function Sidebar() {
32863297
/>
32873298
</TooltipTrigger>
32883299
<TooltipPopup side="right">
3289-
{newThreadShortcutLabel
3290-
? `New thread (${newThreadShortcutLabel})`
3291-
: "New thread"}
3300+
{projectGroups.length > 1 ? (
3301+
<span className="flex flex-col gap-0.5">
3302+
<span>
3303+
{newThreadShortcutLabel
3304+
? `New thread (${newThreadShortcutLabel})`
3305+
: "New thread"}
3306+
</span>
3307+
<span className="text-muted-foreground">
3308+
New thread in current project: Shift+click
3309+
{newThreadInProjectShortcutLabel
3310+
? ` (${newThreadInProjectShortcutLabel})`
3311+
: ""}
3312+
</span>
3313+
</span>
3314+
) : newThreadShortcutLabel ? (
3315+
`New thread (${newThreadShortcutLabel})`
3316+
) : (
3317+
"New thread"
3318+
)}
32923319
</TooltipPopup>
32933320
</Tooltip>
32943321
</div>

0 commit comments

Comments
 (0)