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
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ describe("root reopen shortcut", () => {
expect(useClosedViewStore.getState().entries).toEqual([]);
},
);
it("forwards address-bar focus, zoom, and panel close from a focused desktop page", async () => {
it("forwards address-bar focus, zoom, and panel new and close from a focused desktop page", async () => {
setup();
await using _shortcut = await renderShortcut();
expect(state.setShortcuts).toHaveBeenLastCalledWith(
Expand All @@ -275,6 +275,7 @@ describe("root reopen shortcut", () => {
"preview.zoomIn",
"preview.zoomOut",
"preview.resetZoom",
"rightPanel.new",
"rightPanel.close",
].map((command) => expect.objectContaining({ command })),
),
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/ReopenClosedViewShortcut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const PREVIEW_FORWARDED_COMMANDS = [
"sidebar.toggle",
"rightPanel.toggle",
"rightPanel.toggleMaximized",
"rightPanel.new",
"rightPanel.close",
"preview.focusUrl",
"preview.zoomIn",
Expand Down Expand Up @@ -211,6 +212,7 @@ export function ReopenClosedViewShortcut() {
context: {
previewFocus: true,
previewOpen: true,
rightPanelOpen: true,
terminalFocus: false,
terminalOpen,
editableFocus: false,
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/components/RightPanelTabs.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ function trackpad() {
};
let scrolling = false;
return {
bridge: { onTrackpadScrollBegin: subscribe(begin), onTrackpadScrollEnd: subscribe(end) },
bridge: {
onTrackpadScrollBegin: subscribe(begin),
onTrackpadScrollEnd: subscribe(end),
onMenuAction: () => () => {},
},
scroll(target: Element, deltas: readonly number[]) {
let scroller: Element | null = target;
while (
Expand Down
17 changes: 14 additions & 3 deletions apps/web/src/components/RightPanelTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ export function RightPanelTabs(props: RightPanelTabsProps) {

if (props.open === false && addSurfaceMenuOpen) setAddSurfaceMenuOpen(false);

const addSurfaceMenuBlocked = () =>
!addSurfaceMenuOpen && document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS) !== null;
const onNewSurfaceKeyDown = useEffectEvent((event: KeyboardEvent) => {
if (event.defaultPrevented || event.isComposing) return;
if (
Expand All @@ -1125,19 +1127,28 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
}) !== "rightPanel.new"
)
return;
if (!addSurfaceMenuOpen && document.querySelector(LAUNCHER_SHORTCUT_BLOCKING_LAYERS)) return;
if (addSurfaceMenuBlocked()) return;
event.preventDefault();
event.stopPropagation();
if (!event.repeat) {
addSurfaceTriggerRef.current?.focus();
setAddSurfaceMenuOpen(true);
}
});
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a document keydown listener for the new surface shortcut while the panel is open
// Forwarded from a focused browser page. Focusing the trigger here would let ChatView's
// window-focus handler see a plain button and refocus the composer, closing the menu.
const onMenuAction = useEffectEvent((action: string) => {
if (action === "rightPanel.new" && !addSurfaceMenuBlocked()) setAddSurfaceMenuOpen(true);
});
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes document keydown and the desktop menu action (forwarded from a focused browser page) for the new surface shortcut while the panel is open
useEffect(() => {
if (props.open === false) return;
document.addEventListener("keydown", onNewSurfaceKeyDown, true);
return () => document.removeEventListener("keydown", onNewSurfaceKeyDown, true);
const unsubscribe = window.desktopBridge?.onMenuAction(onMenuAction);
return () => {
document.removeEventListener("keydown", onNewSurfaceKeyDown, true);
unsubscribe?.();
};
}, [props.open]);

const updateTabScrollState = (viewport: HTMLDivElement) => {
Expand Down
Loading