Skip to content

Commit 54c2999

Browse files
committed
fix(web): J and K step the review guide beside a chat
The chat's type-to-focus handler took j and k before the guide tour's listener saw them, so the keys typed into the composer and the tour did not step. The reader's last click or focus now decides which side gets the keys. The tour marks itself while it is the tab on screen with more than one stop, and type-to-focus leaves unshifted j and k to it when the last click or focus landed in the right panel. Fixes #18300
1 parent bed9239 commit 54c2999

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,19 @@ function eventPathContainsSelector(event: Event, selector: string): boolean {
763763
}
764764

765765
const SECRET_REQUEST_SELECTOR = '[data-v2-item-type="secret_request"]';
766+
const RIGHT_PANEL_CONTENT_SELECTOR = "[data-right-panel-surface-content]";
767+
const GUIDE_TOUR_KEYS_SELECTOR = "[data-guide-tour-keys]";
768+
769+
/**
770+
* Whether a review guide on screen takes this key instead of the composer.
771+
* The guide steps on J and K, and stepping drops focus to the body, so the
772+
* reader's last click or focus decides whose key it is, not the event target.
773+
*/
774+
function guideTourTakesKey(event: KeyboardEvent, rightPanelEngaged: boolean): boolean {
775+
if (!rightPanelEngaged || event.shiftKey) return false;
776+
if (event.key !== "j" && event.key !== "k") return false;
777+
return document.querySelector(GUIDE_TOUR_KEYS_SELECTOR) !== null;
778+
}
766779

767780
/**
768781
* Whether input that landed outside any editable or interactive element
@@ -8020,6 +8033,19 @@ export default function ChatView(props: ChatViewProps) {
80208033
const openThreadFind = useCallback(() => threadFindControlsRef.current?.open(), []);
80218034
const closeThreadFind = useCallback(() => threadFindControlsRef.current?.close(), []);
80228035

8036+
const rightPanelEngagedRef = useRef(false);
8037+
useEffect(() => {
8038+
const record = (event: Event) => {
8039+
rightPanelEngagedRef.current = eventPathContainsSelector(event, RIGHT_PANEL_CONTENT_SELECTOR);
8040+
};
8041+
window.addEventListener("pointerdown", record, true);
8042+
window.addEventListener("focusin", record, true);
8043+
return () => {
8044+
window.removeEventListener("pointerdown", record, true);
8045+
window.removeEventListener("focusin", record, true);
8046+
};
8047+
}, []);
8048+
80238049
useEffect(() => {
80248050
const handler = (event: globalThis.KeyboardEvent) => {
80258051
if (preventRepeatedTerminalCloseShortcut(event, keybindings)) {
@@ -8044,6 +8070,7 @@ export default function ChatView(props: ChatViewProps) {
80448070
if (
80458071
!shortcutContext.terminalFocus &&
80468072
!shortcutContext.modelPickerOpen &&
8073+
!guideTourTakesKey(event, rightPanelEngagedRef.current) &&
80478074
shouldTypeToFocusComposer(event)
80488075
) {
80498076
if (composerRef.current?.insertTextAtEnd(event.key)) {

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2945,7 +2945,7 @@ export function PullRequestDetailPanel({
29452945
<PullRequestGuideTab
29462946
environmentId={environmentId}
29472947
reference={reference}
2948-
active={tab === "guide"}
2948+
active={tab === "guide" && shortcutsEnabled}
29492949
title={detail.title}
29502950
workspaceRoot={detail.workspaceRoot}
29512951
canComment={

‎apps/web/src/components/pullRequest/guide/GuideTour.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ export function GuideTour({
117117
return (
118118
// Three widths: one column with the rail folded; the rail beside the stop; and, on a
119119
// maximized panel, the stop's notes in a column of their own (see GuideStop).
120-
<div ref={scrollRef} className="@container/guide h-full overflow-y-auto scrollbar-gutter-both">
120+
<div
121+
ref={scrollRef}
122+
// The chat's type-to-focus reads this to leave J and K to the tour.
123+
data-guide-tour-keys={active && stopCount > 1 ? "jk" : undefined}
124+
className="@container/guide h-full overflow-y-auto scrollbar-gutter-both"
125+
>
121126
<div className="mx-auto grid max-w-[100rem] gap-6 px-4 py-4 @min-[56rem]/guide:grid-cols-[16rem_minmax(0,1fr)] @min-[90rem]/guide:gap-8 @min-[90rem]/guide:px-6">
122127
{/* Beside the stop on a wide panel; narrow, the stop folds the same list open under its
123128
header instead. */}

0 commit comments

Comments
 (0)