Skip to content
Open
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
16 changes: 9 additions & 7 deletions packages/session-ui/src/v2/components/session-review-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ export function SessionReviewV2(props: SessionReviewV2Props) {
}

const prev = () => {
return props.files[fileIndex() - 1]
if (!canCycle()) return
return props.files[(fileIndex() - 1 + props.files.length) % props.files.length]
}

const next = () => {
return props.files[fileIndex() + 1]
if (!canCycle()) return
return props.files[(fileIndex() + 1) % props.files.length]
}

const canCycle = () => props.files.length > 0
Expand All @@ -183,15 +185,15 @@ export function SessionReviewV2(props: SessionReviewV2Props) {
props.onSelectFile(file)
}

// The prev/next tooltips advertise < and >; keep the keys working while the
// Keep the advertised arrow keys working while the
// pane is mounted, but never while typing in an input or comment editor.
makeEventListener(document, "keydown", (event) => {
if (event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey) return
if (event.key !== "<" && event.key !== ">") return
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return
const target = event.target
if (target instanceof HTMLElement && (target.isContentEditable || target.closest("input, textarea, select"))) return
if (!props.hasDiffs || !canCycle()) return
const file = event.key === "<" ? prev() : next()
const file = event.key === "ArrowLeft" ? prev() : next()
if (!file) return
event.preventDefault()
cycle(file)
Expand Down Expand Up @@ -219,7 +221,7 @@ export function SessionReviewV2(props: SessionReviewV2Props) {
value={
<>
{i18n.t("ui.sessionReviewV2.previousFile")}
<KeybindV2 keys={["<"]} variant="neutral" />
<KeybindV2 keys={[""]} variant="neutral" />
</>
}
>
Expand All @@ -239,7 +241,7 @@ export function SessionReviewV2(props: SessionReviewV2Props) {
value={
<>
{i18n.t("ui.sessionReviewV2.nextFile")}
<KeybindV2 keys={[">"]} variant="neutral" />
<KeybindV2 keys={[""]} variant="neutral" />
</>
}
>
Expand Down
Loading