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
1 change: 1 addition & 0 deletions apps/desktop/src/preview/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
if (
forwarded.command === "workspace.focusNext" ||
forwarded.command === "workspace.focusPrevious" ||
forwarded.command === "sidebar.focusThreads" ||
forwarded.command === "preview.focusUrl"
) {
// DOM focus in the renderer cannot by itself release the guest's native keyboard focus.
Expand Down
65 changes: 49 additions & 16 deletions apps/web/src/components/AppSidebarLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
} from "react";
import { useLocation, useRouter, type AnyRouter } from "@tanstack/react-router";

import { moveWorkspaceFocus, workspaceAreaProps } from "../lib/workspaceFocus";
import {
moveWorkspaceFocus,
requestWorkspaceFocus,
workspaceAreaProps,
} from "../lib/workspaceFocus";
import { isCommandPaletteOpen } from "../commandPaletteBus";
import { isElectron } from "../env";
import {
Expand Down Expand Up @@ -319,7 +323,7 @@ function SidebarControl({ showSidebar }: { readonly showSidebar: boolean }) {
const router = useRouter();
const usagePageOpen = useLocation({ select: (location) => location.pathname === "/usage" });
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
const { toggleSidebar } = useSidebar();
const { toggleSidebar, setOpen, setOpenMobile, isMobile } = useSidebar();
const mobileSidebarSheetMounted = useMobileSidebarSheetMounted();
const isSidebarVisible = useSidebarVisibility();
const environmentIdentificationMode = useEnvironmentIdentificationMode();
Expand All @@ -328,10 +332,23 @@ function SidebarControl({ showSidebar }: { readonly showSidebar: boolean }) {
context: { usagePageOpen },
});

// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- window keydown listener that toggles the sidebar on its shortcut
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- window keydown listener that toggles or focuses the sidebar on its shortcuts
useEffect(() => {
// A hidden sidebar would still save the toggle, so the shortcut does nothing without one.
if (!showSidebar) return;
const focusThreads = () => {
if (isMobile) setOpenMobile(true);
else setOpen(true);
requestWorkspaceFocus({
area: "sidebar",
selectors: [
'[data-sidebar-row][aria-current="page"]',
"[data-sidebar-row]",
// A search hides the rows, even with no matches; its combobox owns arrow-key navigation.
'input[role="combobox"][aria-label="Search threads"]:not(:placeholder-shown)',
],
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const onKeyDown = (event: KeyboardEvent) => {
if (event.defaultPrevented) return;
if (
Expand All @@ -349,32 +366,48 @@ function SidebarControl({ showSidebar }: { readonly showSidebar: boolean }) {
// the toggle stays available everywhere else.
return;
}
if (
!isSidebarToggleShortcut(event, keybindings, {
context: {
terminalFocus: isTerminalFocused(),
previewFocus: isPreviewFocused(),
...readRoutePanelsOpen(router),
usagePageOpen,
},
})
)
return;
const options = {
context: {
terminalFocus: isTerminalFocused(),
previewFocus: isPreviewFocused(),
...readRoutePanelsOpen(router),
usagePageOpen,
},
};
const toggle = isSidebarToggleShortcut(event, keybindings, options);
const command = toggle
? "sidebar.toggle"
: resolveShortcutCommand(event, keybindings, options);
if (!toggle && command !== "sidebar.focusThreads") return;
if (command === "sidebar.focusThreads" && isCommandPaletteOpen()) return;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

event.preventDefault();
event.stopPropagation();
toggleSidebar();
if (command === "sidebar.toggle") toggleSidebar();
else if (!event.repeat) focusThreads();
};

window.addEventListener("keydown", onKeyDown, true);
const unsubscribe = window.desktopBridge?.onMenuAction((action) => {
if (action === "sidebar.toggle") toggleSidebar();
});
// Menu action so the command palette and forwarded preview keys reach it too.
const unregisterFocusThreads = registerMenuAction("sidebar.focusThreads", focusThreads);
return () => {
window.removeEventListener("keydown", onKeyDown, true);
unsubscribe?.();
unregisterFocusThreads();
};
}, [keybindings, router, showSidebar, toggleSidebar, usagePageOpen]);
}, [
isMobile,
keybindings,
router,
setOpen,
setOpenMobile,
showSidebar,
toggleSidebar,
usagePageOpen,
]);

// The control lives as long as the shell, so it carries the shell's commands. Created
// once so re-renders never re-register them.
Expand Down
20 changes: 20 additions & 0 deletions apps/web/src/components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import { useDesktopLocalBootstraps } from "../connection/useDesktopLocalBootstra
import { useHandleNewThread } from "../hooks/useHandleNewThread";
import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl";
import { copyThreadReference } from "../lib/copyThreadReference";
import { dispatchMenuAction } from "../shortcuts/dispatcher";
import {
queueWorkspaceFocusFromPalette,
restoreWorkspaceFocusFromPalette,
Expand Down Expand Up @@ -1793,6 +1794,25 @@ function OpenCommandPaletteDialog(props: {
});
}

actionItems.push({
kind: "action",
value: "action:sidebar-focus-threads",
title: gt("Focus Thread List"),
searchTerms: [
gt("Focus Thread List"),
"Focus Thread List",
"sidebar",
"threads",
"focus",
"accessibility",
],
icon: <MonitorIcon className={ITEM_ICON_CLASS} />,
shortcutCommand: "sidebar.focusThreads",
run: async () => {
dispatchMenuAction("sidebar.focusThreads");
},
});

actionItems.push({
kind: "action",
value: "action:settings",
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/ReopenClosedViewShortcut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const PREVIEW_FORWARDED_COMMANDS = [
"workspace.focusNext",
"workspace.focusPrevious",
"sidebar.toggle",
"sidebar.focusThreads",
"rightPanel.toggle",
"rightPanel.toggleMaximized",
"rightPanel.new",
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/chat/useRightPanelActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export function useRightPanelActions(input: RightPanelActionsInput) {
kind !== null && sideThreadComposer(kind) === "composer"
? {
area: "panel",
selector: `[data-side-chat-pane="${CSS.escape(surface.threadId)}"] [data-workspace-area="composer"] [contenteditable="true"]`,
selectors: [
`[data-side-chat-pane="${CSS.escape(surface.threadId)}"] [data-workspace-area="composer"] [contenteditable="true"]`,
],
}
: { area: "panel" },
);
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/files/BrowserDocumentFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const HTML_RENDER_SHORTCUT_COMMANDS: ReadonlySet<KeybindingCommand> = new Set([
"projectSearch.toggle",
"chat.find",
"sidebar.toggle",
"sidebar.focusThreads",
"rightPanel.toggle",
"rightPanel.toggleMaximized",
"threadPanel.toggle",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/files/FilePreviewPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ export default function FilePreviewPanel({
);
const path = row?.getAttribute("data-item-path");
if (!path || path.endsWith("/")) return;
requestWorkspaceFocus({ area: "panel", selector: "[data-file-content-focus]" });
requestWorkspaceFocus({ area: "panel", selectors: ["[data-file-content-focus]"] });
};
const rendered = isMermaid
? renderMermaid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ const COMMAND_LABELS: Partial<Record<KeybindingCommand, string>> = {
"thread.editQueuedMessage": msg("Queue: Edit Last Queued Message"),
"thread.copyReference": msg("Pull Request: Copy Link or Thread"),
"sidebar.toggle": msg("Sidebar: Toggle"),
"sidebar.focusThreads": msg("Sidebar: Focus Thread List"),
"navigation.back": msg("Navigation: Back"),
"navigation.forward": msg("Navigation: Forward"),
"terminal.toggle": msg("Terminal: Toggle"),
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -12781,5 +12781,7 @@
"99d51127f573296b": "Weiteres Konto",
"8ec2c57414669b79": "Verbinde einen zweiten {tracker}-Workspace oder -Nutzer.",
"99963c0142e17f00": "Für das neue {tracker}-Konto.",
"6d8e4ebc889bace9": "Konto hinzufügen"
"6d8e4ebc889bace9": "Konto hinzufügen",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12790,5 +12790,7 @@
"99d51127f573296b": "Another account",
"8ec2c57414669b79": "Connect a second {tracker} workspace or user.",
"99963c0142e17f00": "For the new {tracker} account.",
"6d8e4ebc889bace9": "Add account"
"6d8e4ebc889bace9": "Add account",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -12776,5 +12776,7 @@
"99d51127f573296b": "Otra cuenta",
"8ec2c57414669b79": "Conecta un segundo espacio de trabajo o usuario de {tracker}.",
"99963c0142e17f00": "Para la nueva cuenta de {tracker}.",
"6d8e4ebc889bace9": "Añadir cuenta"
"6d8e4ebc889bace9": "Añadir cuenta",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -12781,5 +12781,7 @@
"99d51127f573296b": "Autre compte",
"8ec2c57414669b79": "Connectez un second espace de travail ou utilisateur {tracker}.",
"99963c0142e17f00": "Pour le nouveau compte {tracker}.",
"6d8e4ebc889bace9": "Ajouter un compte"
"6d8e4ebc889bace9": "Ajouter un compte",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -12722,5 +12722,7 @@
"99d51127f573296b": "別のアカウント",
"8ec2c57414669b79": "2つ目の {tracker} ワークスペースまたはユーザーを接続します。",
"99963c0142e17f00": "新しい {tracker} アカウント用です。",
"6d8e4ebc889bace9": "アカウントを追加"
"6d8e4ebc889bace9": "アカウントを追加",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -12718,5 +12718,7 @@
"99d51127f573296b": "다른 계정",
"8ec2c57414669b79": "두 번째 {tracker} 워크스페이스 또는 사용자를 연결합니다.",
"99963c0142e17f00": "새 {tracker} 계정용입니다.",
"6d8e4ebc889bace9": "계정 추가"
"6d8e4ebc889bace9": "계정 추가",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -12781,5 +12781,7 @@
"99d51127f573296b": "Outra conta",
"8ec2c57414669b79": "Conecte um segundo espaço de trabalho ou usuário do {tracker}.",
"99963c0142e17f00": "Para a nova conta do {tracker}.",
"6d8e4ebc889bace9": "Adicionar conta"
"6d8e4ebc889bace9": "Adicionar conta",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -12781,5 +12781,7 @@
"99d51127f573296b": "Другой аккаунт",
"8ec2c57414669b79": "Подключите второе рабочее пространство или пользователя {tracker}.",
"99963c0142e17f00": "Для нового аккаунта {tracker}.",
"6d8e4ebc889bace9": "Добавить аккаунт"
"6d8e4ebc889bace9": "Добавить аккаунт",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -12788,5 +12788,7 @@
"99d51127f573296b": "Ett konto till",
"8ec2c57414669b79": "Anslut en andra {tracker}-arbetsyta eller användare.",
"99963c0142e17f00": "För det nya {tracker}-kontot.",
"6d8e4ebc889bace9": "Lägg till konto"
"6d8e4ebc889bace9": "Lägg till konto",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
4 changes: 3 additions & 1 deletion apps/web/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -12800,5 +12800,7 @@
"99d51127f573296b": "其他账号",
"8ec2c57414669b79": "连接第二个 {tracker} 工作区或用户。",
"99963c0142e17f00": "用于新的 {tracker} 账号。",
"6d8e4ebc889bace9": "添加账号"
"6d8e4ebc889bace9": "添加账号",
"db20c342cc99da0a": "Focus Thread List",
"a473e2167fba8d25": "Sidebar: Focus Thread List"
}
31 changes: 31 additions & 0 deletions apps/web/src/lib/workspaceFocus.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,37 @@ describe("workspace area focus", () => {
await vi.waitFor(() => expect(document.activeElement).toBe(list.button));
});

it("keeps a request made by a capturing window key handler past its own key", async () => {
using fixture = setup();
fixture.area("composer", 2).button.focus();
const requestOnE = (event: KeyboardEvent) => {
if (event.key === "e") fixture.controller.request({ area: "sidebar" });
};
window.addEventListener("keydown", requestOnE, true);
using _listener = {
[Symbol.dispose]: () => window.removeEventListener("keydown", requestOnE, true),
};
await userEvent.keyboard("e");
const sidebar = fixture.area("sidebar", 0);
await vi.waitFor(() => expect(document.activeElement).toBe(sidebar.button));
});

it("focuses the first selector that matches, in selector order", () => {
using fixture = setup();
const sidebar = fixture.area("sidebar", 0);
sidebar.element.insertAdjacentHTML(
"beforeend",
'<button data-sidebar-row="">First thread</button><button data-sidebar-row="" aria-current="page">Current thread</button>',
);
const [first, current] = sidebar.element.querySelectorAll<HTMLElement>("[data-sidebar-row]");
const selectors = ['[data-sidebar-row][aria-current="page"]', "[data-sidebar-row]"];
expect(fixture.controller.focus("sidebar", true, selectors)).toBe(true);
expect(document.activeElement).toBe(current);
current!.removeAttribute("aria-current");
expect(fixture.controller.focus("sidebar", true, selectors)).toBe(true);
expect(document.activeElement).toBe(first);
});

it("keeps focus on a control that React remounted elsewhere", async () => {
using fixture = setup();
fixture.area("composer", 2);
Expand Down
Loading
Loading