PR view and find bar keys come from their hooks; drop their dead key handlers

w and u in the PR view now act on the PR it shows, not the first linked one.
This commit is contained in:
Callum Alpass committed 2026-11-02 23:06:10 +11:00
1 parent 346212ba5f
commit 275a2bcde1
3 files changed
+30 -74

No files matched your search

+2 -17
View File
@@ -777,30 +777,15 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
{ keys: ["enter", "space"], run: () => cycleSetting(settingsIndex ?? 0), hint: "change" }, { keys: ["enter", "space"], run: () => cycleSetting(settingsIndex ?? 0), hint: "change" },
{ keys: ["esc", "q", "h", "←"], run: closeSettings, hint: "close" }, { keys: ["esc", "q", "h", "←"], run: closeSettings, hint: "close" },
); );
const prCommand = (prefix: string) => pullRequests.commands.find((command) => command.id.startsWith(prefix));
const prKey = (key: string, prefix: string, hint: string): Binding | null => {
const command = prCommand(prefix);
return command ? { keys: [key], run: command.run, hint } : null;
};
const pullRequestKeys = keys( const pullRequestKeys = keys(
{ keys: ["j", "↓"], label: "j/k", run: () => scrollBy(1), hint: "scroll" }, { keys: ["j", "↓"], label: "j/k", run: () => scrollBy(1), hint: "scroll" },
{ keys: ["k", "↑"], run: () => scrollBy(-1) }, { keys: ["k", "↑"], run: () => scrollBy(-1) },
{ keys: ["g"], run: () => scrollRef.current?.scrollTo(0) }, { keys: ["g"], run: () => scrollRef.current?.scrollTo(0) },
{ keys: ["G"], run: () => scrollRef.current?.scrollTo(scrollRef.current.scrollHeight) }, { keys: ["G"], run: () => scrollRef.current?.scrollTo(scrollRef.current.scrollHeight) },
prKey("o", "pr-open", "open"), pullRequests.viewKeys,
prKey("r", "pr-refresh", "refresh"),
prKey("c", "pr-comment", "comment"),
prKey("R", "pr-review", "review"),
prKey("a", "pr-actions", "actions"),
prKey("w", "watch-pull-request", "watch"),
prKey("u", "unlink-pull-request", "unlink"),
{ keys: ["esc", "q"], run: pullRequests.close, hint: "close" },
); );
const findKeys = keys( const findKeys = keys(
{ keys: ["enter"], run: () => find.step(1), hint: "next match" }, find.bindings,
{ keys: ["shift+enter"], run: () => find.step(-1), hint: "previous" },
{ keys: ["ctrl+n"], label: "ctrl+n/p", run: () => find.step(1), hint: "match" },
{ keys: ["ctrl+p"], run: () => find.step(-1) },
{ keys: ["esc"], run: () => setMode("nav"), hint: "close find" }, { keys: ["esc"], run: () => setMode("nav"), hint: "close find" },
quitKey, quitKey,
paletteKey, paletteKey,
+19 -46
View File
@@ -1,4 +1,4 @@
import type { CliRenderer, KeyEvent, ScrollBoxRenderable } from "@opentui/core"; import type { CliRenderer } from "@opentui/core";
import type { import type {
GitPreparePullRequestThreadResult, GitPreparePullRequestThreadResult,
OrchestrationProjectShell, OrchestrationProjectShell,
@@ -22,6 +22,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
import type { T3Session } from "../client/session.ts"; import type { T3Session } from "../client/session.ts";
import { pullRequestItems, type ComposerItem } from "../model/composerMenu.ts"; import { pullRequestItems, type ComposerItem } from "../model/composerMenu.ts";
import { keys, type Binding } from "../model/keymap.ts";
import type { PaletteCommand, Picker } from "../model/palette.ts"; import type { PaletteCommand, Picker } from "../model/palette.ts";
import { import {
COMPOSER_PULL_REQUEST_LIST_LIMIT, COMPOSER_PULL_REQUEST_LIST_LIMIT,
@@ -417,50 +418,22 @@ export function usePullRequests(deps: PullRequestDeps) {
} }
: null; : null;
/** Keys inside the PR view. Returns true when handled. */ /** Keys inside the PR view, for the PR it shows. */
const handleKey = (key: KeyEvent, scroll: ScrollBoxRenderable | null): boolean => { const current = loaded;
if (!loadedRef.current) return false; const viewKeys: Binding[] = current
const current = loadedRef.current; ? keys(
switch (key.name) { { keys: ["o"], run: openInBrowser, hint: "open" },
case "j": { keys: ["r"], run: refresh, hint: "refresh" },
case "down": current.detail && [
scroll?.scrollBy(1); { keys: ["c"], run: comment, hint: "comment" },
return true; { keys: ["R"], run: review, hint: "review" },
case "k": { keys: ["a"], run: actions, hint: "actions" },
case "up": ],
scroll?.scrollBy(-1); supportsWatch && (current.link.snapshot === null || current.link.snapshot.state === "open") && { keys: ["w"], run: () => setWatching(current.link, !watchingCurrent), hint: watchingCurrent ? "unwatch" : "watch" },
return true; { keys: ["u"], run: () => unlink(current.link), hint: current.link.source === "stack" ? "dismiss" : "unlink" },
case "g": { keys: ["esc", "q"], run: close, hint: "close" },
if (key.shift) scroll?.scrollTo(scroll.scrollHeight); )
else scroll?.scrollTo(0); : [];
return true;
case "o":
openInBrowser();
return true;
case "r":
if (key.shift) review();
else refresh();
return true;
case "c":
comment();
return true;
case "a":
actions();
return true;
case "w":
if (supportsWatch && (current.link.snapshot === null || current.link.snapshot.state === "open")) setWatching(current.link, !watchingCurrent);
return true;
case "u":
unlink(current.link);
return true;
case "escape":
case "q":
close();
return true;
default:
return false;
}
};
const commands: (PaletteCommand & { run: () => void })[] = []; const commands: (PaletteCommand & { run: () => void })[] = [];
if (threadShell && links.length > 0) { if (threadShell && links.length > 0) {
@@ -499,7 +472,7 @@ export function usePullRequests(deps: PullRequestDeps) {
commands.push({ id: "pr-refresh", title: "Refresh pull request", shortcut: "r", keywords: ["refresh", "reload"], run: refresh }); commands.push({ id: "pr-refresh", title: "Refresh pull request", shortcut: "r", keywords: ["refresh", "reload"], run: refresh });
} }
return { view, isOpen: loaded !== null, open, close, handleKey, commands }; return { view, isOpen: loaded !== null, open, close, commands, viewKeys };
} }
/** Two links name the same pull request when host, repository and number all match. */ /** Two links name the same pull request when host, repository and number all match. */
+9 -11
View File
@@ -1,7 +1,7 @@
import type { KeyEvent } from "@opentui/core";
import type { OrchestrationV2SearchThreadResult, ThreadId } from "@t3tools/contracts"; import type { OrchestrationV2SearchThreadResult, ThreadId } from "@t3tools/contracts";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import type { T3Session, ThreadState } from "../client/session.ts"; import type { T3Session, ThreadState } from "../client/session.ts";
import type { Binding } from "../model/keymap.ts";
import type { Timeline } from "../model/timeline.ts"; import type { Timeline } from "../model/timeline.ts";
import { stepThreadFindIndex } from "../../vendor/t3code/apps/web/src/components/chat/threadFind.ts"; import { stepThreadFindIndex } from "../../vendor/t3code/apps/web/src/components/chat/threadFind.ts";
@@ -62,15 +62,13 @@ export function useThreadFind(session: T3Session, id: ThreadId | undefined, thre
if (data) setIndex(stepThreadFindIndex(data.activeIndex, data.totalMatches, delta)); if (data) setIndex(stepThreadFindIndex(data.activeIndex, data.totalMatches, delta));
}; };
const handleKey = (keyEvent: KeyEvent): boolean => { /** While the find bar has the keys, next to the query field. */
if (!open) return false; const bindings: Binding[] = [
if (keyEvent.name === "escape") return true; { keys: ["enter"], run: () => step(1), hint: "next match" },
if (keyEvent.name === "return") step(keyEvent.shift ? -1 : 1); { keys: ["shift+enter"], run: () => step(-1), hint: "previous" },
else if (keyEvent.ctrl && keyEvent.name === "n") step(1); { keys: ["ctrl+n"], label: "ctrl+n/p", run: () => step(1), hint: "match" },
else if (keyEvent.ctrl && keyEvent.name === "p") step(-1); { keys: ["ctrl+p"], run: () => step(-1) },
else return false; ];
return true;
};
const onQuery = (value: string) => { const onQuery = (value: string) => {
setQuery(value); setQuery(value);
@@ -86,6 +84,6 @@ export function useThreadFind(session: T3Session, id: ThreadId | undefined, thre
error, error,
pending: key !== null && data === null && !error, pending: key !== null && data === null && !error,
step, step,
handleKey, bindings,
}; };
} }