Add mouse support across the TUI
Drag to select copies on release. Request cards, the queue, attachments, the PR view and the key hints get clickable buttons. Prompts, folds, commands and diff files respond to clicks; prompts, replies, commands and the PR view get right-click menus. Clicking a pane focuses it, the wheel scrolls the thread list and palette, rows highlight under the pointer, and the thread list's border drags to resize.
This commit is contained in:
1 parent
fbdfb5c3e0
commit
12e1e0ba7a
27 files changed
+639
-116
No files matched your search
+15
-3
@@ -1,8 +1,9 @@
|
||||
import type { ReviewDiffFileContentsInput } from "@t3tools/contracts";
|
||||
import { splitPatch } from "../model/diffs.ts";
|
||||
import type { ScrollBoxRenderable } from "@opentui/core";
|
||||
import type { MouseEvent, ScrollBoxRenderable } from "@opentui/core";
|
||||
import type { RefObject } from "react";
|
||||
|
||||
import { isLeftClick, useHover } from "./Button.tsx";
|
||||
import { colors, getMarkdownStyle } from "./theme.ts";
|
||||
|
||||
export interface DiffState {
|
||||
@@ -18,7 +19,7 @@ export interface DiffState {
|
||||
}
|
||||
|
||||
/** Working-tree or checkpoint changes through the same unified diff renderer. */
|
||||
export function DiffView(props: { readonly diff: DiffState; readonly scrollRef: RefObject<ScrollBoxRenderable | null>; readonly selected: number; readonly expanded: Readonly<Record<string, { patch?: string; error?: string }>> }) {
|
||||
export function DiffView(props: { readonly diff: DiffState; readonly scrollRef: RefObject<ScrollBoxRenderable | null>; readonly selected: number; readonly expanded: Readonly<Record<string, { patch?: string; error?: string }>>; readonly onFile: (index: number) => void }) {
|
||||
const { diff } = props;
|
||||
const files = diff.patch ? splitPatch(diff.patch) : [];
|
||||
return (
|
||||
@@ -38,7 +39,7 @@ export function DiffView(props: { readonly diff: DiffState; readonly scrollRef:
|
||||
<scrollbox ref={props.scrollRef} flexGrow={1} minHeight={0}>
|
||||
{files.map((file, index) => (
|
||||
<box key={file.path} id={`diff-file-${index}`} flexDirection="column" marginTop={1}>
|
||||
<text fg={index === props.selected ? colors.accent : colors.muted}>{`${index === props.selected ? "▸ " : " "}${file.path}`}</text>
|
||||
<FileHeader path={file.path} selected={index === props.selected} canExpand={diff.source !== undefined} onPress={() => props.onFile(index)} />
|
||||
{props.expanded[file.path] && !props.expanded[file.path]?.patch ? <text fg={props.expanded[file.path]?.error ? colors.bad : colors.muted}>{props.expanded[file.path]?.error ?? "Loading full file…"}</text> : null}
|
||||
<diff
|
||||
diff={props.expanded[file.path]?.patch ?? file.patch}
|
||||
@@ -63,6 +64,17 @@ export function DiffView(props: { readonly diff: DiffState; readonly scrollRef:
|
||||
);
|
||||
}
|
||||
|
||||
/** A click selects the file; a click on the selected one shows its whole file, as x does. */
|
||||
function FileHeader(props: { readonly path: string; readonly selected: boolean; readonly canExpand: boolean; readonly onPress: () => void }) {
|
||||
const [hover, hoverProps] = useHover();
|
||||
return (
|
||||
<box flexDirection="row" {...hoverProps} onMouseDown={(event: MouseEvent) => isLeftClick(event) && props.onPress()}>
|
||||
<text fg={props.selected ? colors.accent : hover ? colors.text : colors.muted} selectable={false}>{`${props.selected ? "▸ " : " "}${props.path}`}</text>
|
||||
{hover && props.selected && props.canExpand ? <text fg={colors.faint} selectable={false}>{" click for the whole file"}</text> : null}
|
||||
</box>
|
||||
);
|
||||
}
|
||||
|
||||
export { splitPatch } from "../model/diffs.ts";
|
||||
|
||||
const FILETYPES: Record<string, string> = { ts: "typescript", tsx: "tsx", js: "javascript", jsx: "javascript", json: "json", md: "markdown", rs: "rust", py: "python", go: "go", css: "css", html: "html", sh: "bash", yml: "yaml", yaml: "yaml", zig: "zig" };
|
||||
|
||||
Reference in new issue
Block a user