浏览代码

feat(app): update arrow buttons in review tab top bar (#39469)

Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com>
Aarav Sareen 1 月之前
父节点
当前提交
73009f0b09
共有 1 个文件被更改,包括 9 次插入7 次删除
  1. 9 7
      packages/session-ui/src/v2/components/session-review-v2.tsx

+ 9 - 7
packages/session-ui/src/v2/components/session-review-v2.tsx

@@ -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
@@ -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)
@@ -219,7 +221,7 @@ export function SessionReviewV2(props: SessionReviewV2Props) {
           value={
             <>
               {i18n.t("ui.sessionReviewV2.previousFile")}
-              <KeybindV2 keys={["<"]} variant="neutral" />
+              <KeybindV2 keys={[""]} variant="neutral" />
             </>
           }
         >
@@ -239,7 +241,7 @@ export function SessionReviewV2(props: SessionReviewV2Props) {
           value={
             <>
               {i18n.t("ui.sessionReviewV2.nextFile")}
-              <KeybindV2 keys={[">"]} variant="neutral" />
+              <KeybindV2 keys={[""]} variant="neutral" />
             </>
           }
         >