feat(shortcuts): copy active thread reference (#8994)

Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
mariaandmaria-rcks authored and GitHub committed 2026-09-01 12:48:56 -04:00
1 parent b5b6abb11e
commit 2d156a83b9
20 files changed
+500 -16

No files matched your search

@@ -0,0 +1,46 @@
package expo.modules.t3nativecontrols
import android.content.Context
import android.view.KeyEvent
import expo.modules.kotlin.AppContext
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import expo.modules.kotlin.viewevent.EventDispatcher
import expo.modules.kotlin.views.ExpoView
class T3KeyboardCommandsModule : Module() {
override fun definition() = ModuleDefinition {
Name("T3KeyboardCommands")
View(T3KeyboardCommandsView::class) {
Prop("enabledCommands") { view: T3KeyboardCommandsView, commands: List<String> ->
view.enabledCommands = commands.toSet()
}
Events("onCommand")
}
}
}
class T3KeyboardCommandsView(
context: Context,
appContext: AppContext
) : ExpoView(context, appContext) {
private val onCommand by EventDispatcher()
var enabledCommands = emptySet<String>()
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
val copiesThreadReference =
event.action == KeyEvent.ACTION_DOWN &&
event.repeatCount == 0 &&
event.keyCode == KeyEvent.KEYCODE_C &&
event.isCtrlPressed &&
event.isShiftPressed &&
!event.isAltPressed &&
enabledCommands.contains("copyThreadReference")
if (copiesThreadReference) {
onCommand(mapOf("command" to "copyThreadReference"))
return true
}
return super.dispatchKeyEvent(event)
}
}
@@ -4,6 +4,9 @@
"modules": ["T3NativeControlsModule", "T3KeyboardCommandsModule"]
},
"android": {
"modules": ["expo.modules.t3nativecontrols.T3NativeControlsModule"]
"modules": [
"expo.modules.t3nativecontrols.T3NativeControlsModule",
"expo.modules.t3nativecontrols.T3KeyboardCommandsModule"
]
}
}
@@ -29,6 +29,13 @@ public final class T3KeyboardCommandsView: ExpoView {
enabledCommand("files", input: "f", modifiers: [.command, .shift], action: #selector(openFiles), title: "Open Files"),
enabledCommand("terminal", input: "t", modifiers: [.command, .shift], action: #selector(openTerminal), title: "Open Terminal"),
enabledCommand("review", input: "r", modifiers: [.command, .shift], action: #selector(openReview), title: "Open Review"),
enabledCommand(
"copyThreadReference",
input: "c",
modifiers: [.command, .shift],
action: #selector(copyThreadReference),
title: "Copy PR Link or Thread ID"
),
enabledCommand("toggleSidebar", input: "\\", modifiers: .command, action: #selector(handleToggleSidebar), title: "Toggle Sidebar"),
].compactMap { $0 }
}
@@ -106,6 +113,7 @@ public final class T3KeyboardCommandsView: ExpoView {
@objc private func openFiles() { emit("files") }
@objc private func openTerminal() { emit("terminal") }
@objc private func openReview() { emit("review") }
@objc private func copyThreadReference() { emit("copyThreadReference") }
@objc private func handleToggleSidebar() { emit("toggleSidebar") }
private func emit(_ command: String) {
@@ -1,7 +1,22 @@
import { StackActions, useNavigation } from "@react-navigation/native";
import { useCallback, useMemo, useSyncExternalStore, type PropsWithChildren } from "react";
import { resolveThreadReferenceCopyTarget } from "@t3tools/shared/threadReference";
import {
useCallback,
useEffect,
useMemo,
useRef,
useState,
useSyncExternalStore,
type PropsWithChildren,
} from "react";
import { tryCopyTextWithHaptic } from "../../lib/copyTextWithHaptic";
import { T3KeyboardCommands } from "../../native/T3KeyboardCommands";
import { useProject, useThreadShell } from "../../state/entities";
import { useEnvironmentQuery } from "../../state/query";
import type { GitActionProgress } from "../../state/use-vcs-action-state";
import { vcsEnvironment } from "../../state/vcs";
import { GitActionProgressOverlay } from "../threads/GitActionProgressOverlay";
import {
dispatchHardwareKeyboardCommand,
getHardwareKeyboardCommandRegistrationVersion,
@@ -11,11 +26,86 @@ import {
type HardwareKeyboardCommand,
} from "./hardwareKeyboardCommands";
const EMPTY_COPY_FEEDBACK: GitActionProgress = {
phase: "idle",
label: null,
description: null,
};
const COPY_FEEDBACK_DISMISS_MS = 3_000;
export function HardwareKeyboardCommandProvider({
children,
pathname,
}: PropsWithChildren<{ readonly pathname: string }>) {
const navigation = useNavigation();
const activeThreadRef = useMemo(() => parseActiveThreadPath(pathname), [pathname]);
const activeThread = useThreadShell(activeThreadRef);
const activeProjectRef = useMemo(
() =>
activeThread === null
? null
: {
environmentId: activeThread.environmentId,
projectId: activeThread.projectId,
},
[activeThread],
);
const activeProject = useProject(activeProjectRef);
const activeThreadCwd = activeThread?.worktreePath ?? activeProject?.workspaceRoot ?? null;
const gitStatus = useEnvironmentQuery(
activeThread !== null &&
activeThread.linkedPullRequest == null &&
activeThread.branch !== null &&
activeThreadCwd !== null
? vcsEnvironment.status({
environmentId: activeThread.environmentId,
input: { cwd: activeThreadCwd },
})
: null,
).data;
const detectedPullRequestUrl =
activeThread?.branch != null && gitStatus?.refName === activeThread.branch
? (gitStatus.pr?.url ?? null)
: null;
const copyTarget = useMemo(
() =>
activeThreadRef === null
? null
: resolveThreadReferenceCopyTarget({
threadId: activeThread?.id ?? activeThreadRef.threadId,
linkedPullRequestUrl: activeThread?.linkedPullRequest?.url ?? null,
detectedPullRequestUrl,
}),
[activeThread, activeThreadRef, detectedPullRequestUrl],
);
const [copyFeedback, setCopyFeedback] = useState<GitActionProgress>(EMPTY_COPY_FEEDBACK);
const copyRequestIdRef = useRef(0);
const copyFeedbackTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const dismissCopyFeedback = useCallback(() => {
if (copyFeedbackTimerRef.current !== null) {
clearTimeout(copyFeedbackTimerRef.current);
copyFeedbackTimerRef.current = null;
}
setCopyFeedback(EMPTY_COPY_FEEDBACK);
}, []);
const showCopyFeedback = useCallback((feedback: GitActionProgress) => {
if (copyFeedbackTimerRef.current !== null) {
clearTimeout(copyFeedbackTimerRef.current);
}
setCopyFeedback(feedback);
copyFeedbackTimerRef.current = setTimeout(() => {
copyFeedbackTimerRef.current = null;
setCopyFeedback(EMPTY_COPY_FEEDBACK);
}, COPY_FEEDBACK_DISMISS_MS);
}, []);
useEffect(
() => () => {
if (copyFeedbackTimerRef.current !== null) {
clearTimeout(copyFeedbackTimerRef.current);
}
},
[],
);
const registrationVersion = useSyncExternalStore(
subscribeToHardwareKeyboardCommandRegistrations,
getHardwareKeyboardCommandRegistrationVersion,
@@ -25,10 +115,11 @@ export function HardwareKeyboardCommandProvider({
const commands = new Set<HardwareKeyboardCommand>(getRegisteredHardwareKeyboardCommands());
commands.add("newTask");
if (pathname !== "/" || navigation.canGoBack()) commands.add("back");
if (parseActiveThreadPath(pathname)) {
if (activeThreadRef !== null) {
commands.add("files");
commands.add("terminal");
commands.add("review");
if (pathname.split("/")[4] !== "terminal") commands.add("copyThreadReference");
}
return [...commands];
}, [pathname, registrationVersion, navigation]);
@@ -37,6 +128,30 @@ export function HardwareKeyboardCommandProvider({
(command: HardwareKeyboardCommand) => {
if (dispatchHardwareKeyboardCommand(command)) return;
if (command === "copyThreadReference") {
if (copyTarget === null) return;
const requestId = ++copyRequestIdRef.current;
void tryCopyTextWithHaptic(copyTarget.value, {
target: copyTarget.clipboardTarget,
}).then((didCopy) => {
if (requestId !== copyRequestIdRef.current) return;
showCopyFeedback(
didCopy
? {
phase: "success",
label: copyTarget.successTitle,
description: copyTarget.value,
}
: {
phase: "error",
label: copyTarget.failureTitle,
description: "Try again.",
},
);
});
return;
}
if (command === "newTask") {
navigation.navigate("NewTaskSheet", { screen: "NewTask" });
return;
@@ -62,12 +177,15 @@ export function HardwareKeyboardCommandProvider({
navigation.navigate("ThreadReview", thread);
}
},
[pathname, navigation],
[copyTarget, navigation, pathname, showCopyFeedback],
);
return (
<T3KeyboardCommands enabledCommands={enabledCommands} onCommand={onCommand}>
{children}
</T3KeyboardCommands>
<>
<T3KeyboardCommands enabledCommands={enabledCommands} onCommand={onCommand}>
{children}
</T3KeyboardCommands>
<GitActionProgressOverlay progress={copyFeedback} onDismiss={dismissCopyFeedback} />
</>
);
}
@@ -8,6 +8,7 @@ export type HardwareKeyboardCommand =
| "files"
| "terminal"
| "review"
| "copyThreadReference"
| "toggleSidebar";
type CommandHandler = () => boolean | void;
@@ -22,6 +22,7 @@ import {
CopyTextClipboardWriteError,
CopyTextHapticFeedbackError,
copyTextWithHaptic,
tryCopyTextWithHaptic,
} from "./copyTextWithHaptic";
describe("copyTextWithHaptic", () => {
@@ -54,6 +55,19 @@ describe("copyTextWithHaptic", () => {
expect(mocks.impactAsync).not.toHaveBeenCalled();
});
it("reports whether the clipboard write succeeded", async () => {
mocks.setStringAsync.mockResolvedValueOnce(undefined);
await expect(tryCopyTextWithHaptic("thread-123")).resolves.toBe(true);
});
it("returns false when the clipboard write fails", async () => {
vi.spyOn(console, "error").mockImplementation(() => undefined);
mocks.setStringAsync.mockRejectedValueOnce(new Error("native clipboard failure"));
await expect(tryCopyTextWithHaptic("thread-123")).resolves.toBe(false);
});
it("reports structured failures without including clipboard contents", async () => {
const clipboardCause = new Error("native clipboard failure");
const hapticCause = new Error("native haptic failure");
+17 -7
View File
@@ -27,19 +27,22 @@ export class CopyTextHapticFeedbackError extends Schema.TaggedErrorClass<CopyTex
}
}
export function copyTextWithHaptic(
interface CopyTextWithHapticOptions {
readonly target?: string;
readonly feedback?: "light-impact" | "selection";
}
export async function tryCopyTextWithHaptic(
value: string,
options: {
readonly target?: string;
readonly feedback?: "light-impact" | "selection";
} = {},
): void {
options: CopyTextWithHapticOptions = {},
): Promise<boolean> {
const target = options.target ?? "text";
const feedback = options.feedback ?? "light-impact";
void (async () => {
const clipboardWrite = (async () => {
try {
await Clipboard.setStringAsync(value);
return true;
} catch (cause) {
console.error(
new CopyTextClipboardWriteError({
@@ -47,6 +50,7 @@ export function copyTextWithHaptic(
cause,
}),
);
return false;
}
})();
@@ -67,4 +71,10 @@ export function copyTextWithHaptic(
);
}
})();
return await clipboardWrite;
}
export function copyTextWithHaptic(value: string, options: CopyTextWithHapticOptions = {}): void {
void tryCopyTextWithHaptic(value, options);
}
@@ -0,0 +1,31 @@
import { requireNativeView } from "expo";
import type { PropsWithChildren } from "react";
import type { NativeSyntheticEvent, ViewProps } from "react-native";
import type { HardwareKeyboardCommand } from "../features/keyboard/hardwareKeyboardCommands";
interface NativeKeyboardCommandsProps extends ViewProps, PropsWithChildren {
readonly enabledCommands: ReadonlyArray<HardwareKeyboardCommand>;
readonly onCommand: (
event: NativeSyntheticEvent<{ readonly command: HardwareKeyboardCommand }>,
) => void;
}
const NativeKeyboardCommands = requireNativeView<NativeKeyboardCommandsProps>("T3KeyboardCommands");
export function T3KeyboardCommands(
props: PropsWithChildren<{
readonly enabledCommands: ReadonlyArray<HardwareKeyboardCommand>;
readonly onCommand: (command: HardwareKeyboardCommand) => void;
}>,
) {
return (
<NativeKeyboardCommands
onCommand={(event) => props.onCommand(event.nativeEvent.command)}
enabledCommands={props.enabledCommands}
style={{ flex: 1 }}
>
{props.children}
</NativeKeyboardCommands>
);
}
@@ -54,6 +54,7 @@ function threadDetailToShell(
interactionMode: thread.interactionMode,
branch: thread.branch,
worktreePath: thread.worktreePath,
linkedPullRequest: thread.linkedPullRequest ?? null,
latestTurn: thread.latestTurn,
createdAt: thread.createdAt,
updatedAt: thread.updatedAt,
+1
View File
@@ -195,6 +195,7 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
assert.equal(defaultsByCommand.get("thread.previous"), "mod+shift+[");
assert.equal(defaultsByCommand.get("thread.next"), "mod+shift+]");
assert.equal(defaultsByCommand.get("thread.copyReference"), "mod+shift+c");
assert.equal(defaultsByCommand.get("thread.settle"), "mod+shift+s");
assert.equal(defaultsByCommand.get("thread.pin"), "mod+shift+p");
assert.equal(defaultsByCommand.get("thread.jump.1"), "mod+1");
+44
View File
@@ -50,6 +50,7 @@ import {
} from "@t3tools/shared/model";
import { projectScriptCwd, projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts";
import { truncate } from "@t3tools/shared/String";
import { resolveThreadReferenceCopyTarget } from "@t3tools/shared/threadReference";
import {
getTerminalLabel,
nextTerminalId,
@@ -4593,6 +4594,41 @@ function ChatViewContent(props: ChatViewProps) {
linkedPullRequest: linkedThreadPullRequest,
linkedPullRequestStatus,
});
const activeThreadReferenceCopyTarget = useMemo(
() =>
activeThreadId === null || !isServerThread
? null
: resolveThreadReferenceCopyTarget({
threadId: activeThreadId,
linkedPullRequestUrl: linkedThreadPullRequest?.url ?? null,
detectedPullRequestUrl: activeThreadPr?.url ?? null,
}),
[activeThreadId, activeThreadPr?.url, isServerThread, linkedThreadPullRequest?.url],
);
const copyActiveThreadReference = useCallback(() => {
const target = activeThreadReferenceCopyTarget;
if (target === null) return;
void writeTextToClipboard(target.value, target.clipboardTarget).then(
(didCopy) => {
if (!didCopy) return;
toastManager.add({
type: "success",
title: target.successTitle,
description: target.value,
});
},
(error) => {
console.error(error);
toastManager.add(
stackedThreadToast({
type: "error",
title: target.failureTitle,
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
},
);
}, [activeThreadReferenceCopyTarget]);
// The right panel offers the thread's own change request, so it can only offer it once the
// branch has one; until then the picker says so rather than opening an empty panel.
const addPullRequestSurface = useCallback(() => {
@@ -5257,6 +5293,13 @@ function ChatViewContent(props: ChatViewProps) {
});
if (!command) return;
if (command === "thread.copyReference") {
event.preventDefault();
event.stopPropagation();
if (!event.repeat) copyActiveThreadReference();
return;
}
if (command === "thread.settle") {
event.preventDefault();
event.stopPropagation();
@@ -5426,6 +5469,7 @@ function ChatViewContent(props: ChatViewProps) {
supportsPinning,
supportsSettlement,
confirmAndUnpinThread,
copyActiveThreadReference,
toggleRightPanel,
toggleRightPanelMaximized,
toggleTerminalVisibility,
+90 -2
View File
@@ -1,6 +1,10 @@
"use client";
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
import {
scopedThreadKey,
scopeProjectRef,
scopeThreadRef,
} from "@t3tools/client-runtime/environment";
import {
canCreateProjectInEnvironment,
getCloneDestinationBrowsePath,
@@ -11,6 +15,7 @@ import {
} from "@t3tools/client-runtime/operations/projects";
import { connectionStatusText } from "@t3tools/client-runtime/connection";
import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
import { resolveThreadReferenceCopyTarget } from "@t3tools/shared/threadReference";
import {
canPreloadBrowsePath,
createBrowseNavigationCoordinator,
@@ -65,6 +70,7 @@ import { useAtomValue } from "@effect/atom-react";
import { isDesktopLocalConnectionTarget } from "../connection/desktopLocal";
import { useDesktopLocalBootstraps } from "../connection/useDesktopLocalBootstraps";
import { useHandleNewThread } from "../hooks/useHandleNewThread";
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
import { useClientSettings } from "../hooks/useSettings";
import { useTheme } from "../hooks/useTheme";
import { readLocalApi } from "../localApi";
@@ -73,11 +79,13 @@ import { filesystemEnvironment } from "../state/filesystem";
import { projectEnvironment } from "../state/projects";
import { useEnvironmentQuery } from "../state/query";
import { sourceControlEnvironment } from "../state/sourceControl";
import { vcsEnvironment } from "../state/vcs";
import { useAtomCommand } from "../state/use-atom-command";
import { useAtomQueryRunner } from "../state/use-atom-query-runner";
import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
import { useProjects, useThreadShells } from "../state/entities";
import { useProject, useProjects, useThreadShells } from "../state/entities";
import { useThreadSearch } from "../state/queries";
import * as ThreadPr from "./ThreadStatusIndicators";
import { resolveThreadActionProjectRef, startNewThreadFromContext } from "../lib/chatThreadActions";
import {
appendBrowsePathSegment,
@@ -592,6 +600,65 @@ function OpenCommandPaletteDialog(props: {
const { activeDraftThread, activeThread, defaultProjectRef, handleNewThread } =
useHandleNewThread();
const projects = useProjects();
const changeRequestSnapshotByKey = useAtomValue(ThreadPr.threadChangeRequestSnapshotsAtom);
const activeThreadProject = useProject(
activeThread === null
? null
: scopeProjectRef(activeThread.environmentId, activeThread.projectId),
);
const activeThreadCwd = activeThread?.worktreePath ?? activeThreadProject?.workspaceRoot ?? null;
const activeThreadGitStatus = useEnvironmentQuery(
activeThread != null &&
activeThread.linkedPullRequest == null &&
activeThread.branch !== null &&
activeThreadCwd !== null
? vcsEnvironment.status({
environmentId: activeThread.environmentId,
input: { cwd: activeThreadCwd },
})
: null,
).data;
const detectedPullRequestUrl =
activeThread == null || activeThread.linkedPullRequest != null
? null
: (ThreadPr.resolveDisplayedThreadPr({
threadBranch: activeThread.branch,
gitStatus: activeThreadGitStatus ?? null,
snapshot: changeRequestSnapshotByKey.get(
scopedThreadKey(scopeThreadRef(activeThread.environmentId, activeThread.id)),
),
retainTerminalOnBranchMismatch: activeThread.worktreePath === null,
})?.url ?? null);
const activeThreadReferenceCopyTarget =
activeThread == null
? null
: resolveThreadReferenceCopyTarget({
threadId: activeThread.id,
linkedPullRequestUrl: activeThread.linkedPullRequest?.url ?? null,
detectedPullRequestUrl,
});
const copyActiveThreadReference = useCallback(async () => {
const target = activeThreadReferenceCopyTarget;
if (target === null) return;
try {
const didCopy = await writeTextToClipboard(target.value, target.clipboardTarget);
if (!didCopy) return;
toastManager.add({
type: "success",
title: target.successTitle,
description: target.value,
});
} catch (error) {
console.error(error);
toastManager.add(
stackedThreadToast({
type: "error",
title: target.failureTitle,
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
}
}, [activeThreadReferenceCopyTarget]);
const projectOrder = useUiStateStore((store) => store.projectOrder);
const threads = useThreadShells();
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
@@ -1529,6 +1596,20 @@ function OpenCommandPaletteDialog(props: {
});
}
if (activeThreadReferenceCopyTarget !== null) {
actionItems.push({
kind: "action",
value: "action:copy-thread-reference",
searchTerms: ["copy", "pull request", "pr link", "thread id", "reference"],
title:
activeThreadReferenceCopyTarget.kind === "pull-request" ? "Copy PR link" : "Copy thread ID",
description: activeThreadReferenceCopyTarget.value,
icon: <LinkIcon className={ITEM_ICON_CLASS} />,
shortcutCommand: "thread.copyReference",
run: copyActiveThreadReference,
});
}
actionItems.push({
kind: "action",
value: "action:open-file-picker",
@@ -2203,6 +2284,13 @@ function OpenCommandPaletteDialog(props: {
return;
}
}
if (command === "thread.copyReference" && activeThreadReferenceCopyTarget !== null) {
event.preventDefault();
event.stopPropagation();
setOpen(false);
void copyActiveThreadReference();
return;
}
if (addProjectCloneFlow?.step === "repository" && event.key === "Enter") {
event.preventDefault();
+31
View File
@@ -142,6 +142,11 @@ const DEFAULT_BINDINGS = compile([
{ shortcut: modShortcut("o"), command: "editor.openFavorite" },
{ shortcut: modShortcut("[", { shiftKey: true }), command: "thread.previous" },
{ shortcut: modShortcut("]", { shiftKey: true }), command: "thread.next" },
{
shortcut: modShortcut("c", { shiftKey: true }),
command: "thread.copyReference",
whenAst: whenNot(whenIdentifier("terminalFocus")),
},
{
shortcut: modShortcut("s", { shiftKey: true }),
command: "thread.settle",
@@ -213,6 +218,32 @@ describe("settle thread shortcut", () => {
});
});
describe("copy thread reference shortcut", () => {
it("resolves Cmd+Shift+C on macOS and Ctrl+Shift+C elsewhere", () => {
assert.equal(
resolveShortcutCommand(event({ key: "c", metaKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
platform: "MacIntel",
}),
"thread.copyReference",
);
assert.equal(
resolveShortcutCommand(event({ key: "c", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
platform: "Linux",
}),
"thread.copyReference",
);
});
it("leaves terminal copy untouched", () => {
assert.isNull(
resolveShortcutCommand(event({ key: "c", ctrlKey: true, shiftKey: true }), DEFAULT_BINDINGS, {
platform: "Linux",
context: { terminalFocus: true },
}),
);
});
});
describe("split/new/close terminal shortcuts", () => {
it("requires terminalFocus for default split/new/close bindings", () => {
assert.isFalse(
+4
View File
@@ -52,6 +52,10 @@ successful pick; its hover glow and badge preview the element and color family t
`rightPanel.toggleMaximized` maximizes or restores the open right panel. It has no default shortcut,
so add one in **Settings** → **Keybindings** if you want to use it.
`thread.copyReference` copies the active thread's pull request link, or its thread ID when no pull
request is available. Its default shortcut is `mod+shift+c`, and it does not replace terminal copy
while the terminal has focus.
`thread.settle` settles the active thread or restores it when it is already settled. Its default
shortcut is `mod+shift+s`, and it does not run while the terminal has focus.
@@ -114,6 +114,13 @@ it.effect("parses keybinding rules", () =>
when: "!terminalFocus",
});
assert.strictEqual(parsedThreadSettle.command, "thread.settle");
const parsedThreadCopyReference = yield* decode(KeybindingRule, {
key: "mod+shift+c",
command: "thread.copyReference",
when: "!terminalFocus",
});
assert.strictEqual(parsedThreadCopyReference.command, "thread.copyReference");
}),
);
+1
View File
@@ -37,6 +37,7 @@ export type ModelPickerJumpKeybindingCommand =
export const THREAD_KEYBINDING_COMMANDS = [
"thread.previous",
"thread.next",
"thread.copyReference",
"thread.settle",
"thread.pin",
...THREAD_JUMP_KEYBINDING_COMMANDS,
+4
View File
@@ -167,6 +167,10 @@
"types": "./src/keybindings.ts",
"import": "./src/keybindings.ts"
},
"./threadReference": {
"types": "./src/threadReference.ts",
"import": "./src/threadReference.ts"
},
"./composerTrigger": {
"types": "./src/composerTrigger.ts",
"import": "./src/composerTrigger.ts"
+1
View File
@@ -46,6 +46,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
{ key: "mod+o", command: "editor.openFavorite" },
{ key: "mod+shift+[", command: "thread.previous" },
{ key: "mod+shift+]", command: "thread.next" },
{ key: "mod+shift+c", command: "thread.copyReference", when: "!terminalFocus" },
{ key: "mod+shift+s", command: "thread.settle", when: "!terminalFocus" },
{ key: "mod+shift+p", command: "thread.pin", when: "!terminalFocus" },
...THREAD_JUMP_KEYBINDING_COMMANDS.map((command, index) => ({
@@ -0,0 +1,41 @@
import { describe, expect, it } from "vite-plus/test";
import { resolveThreadReferenceCopyTarget } from "./threadReference.ts";
describe("resolveThreadReferenceCopyTarget", () => {
it("prefers a durable linked pull request", () => {
expect(
resolveThreadReferenceCopyTarget({
threadId: "thread-1",
linkedPullRequestUrl: "https://github.com/t3/pr/12",
detectedPullRequestUrl: "https://github.com/t3/pr/13",
}),
).toMatchObject({
kind: "pull-request",
value: "https://github.com/t3/pr/12",
successTitle: "PR link copied",
});
});
it("uses a pull request detected from the active branch", () => {
expect(
resolveThreadReferenceCopyTarget({
threadId: "thread-1",
detectedPullRequestUrl: "https://github.com/t3/pr/13",
}),
).toMatchObject({
kind: "pull-request",
value: "https://github.com/t3/pr/13",
});
});
it("falls back to the thread ID", () => {
expect(resolveThreadReferenceCopyTarget({ threadId: "thread-1" })).toEqual({
kind: "thread",
value: "thread-1",
clipboardTarget: "thread ID",
successTitle: "Thread ID copied",
failureTitle: "Failed to copy thread ID",
});
});
});
+30
View File
@@ -0,0 +1,30 @@
export interface ThreadReferenceCopyTarget {
readonly kind: "pull-request" | "thread";
readonly value: string;
readonly clipboardTarget: string;
readonly successTitle: string;
readonly failureTitle: string;
}
export function resolveThreadReferenceCopyTarget(input: {
readonly threadId: string;
readonly linkedPullRequestUrl?: string | null;
readonly detectedPullRequestUrl?: string | null;
}): ThreadReferenceCopyTarget {
const pullRequestUrl = input.linkedPullRequestUrl ?? input.detectedPullRequestUrl;
return pullRequestUrl
? {
kind: "pull-request",
value: pullRequestUrl,
clipboardTarget: "pull request link",
successTitle: "PR link copied",
failureTitle: "Failed to copy PR link",
}
: {
kind: "thread",
value: input.threadId,
clipboardTarget: "thread ID",
successTitle: "Thread ID copied",
failureTitle: "Failed to copy thread ID",
};
}