@devries-cameron20 / t3code Mirror · read-only / commits / 2d81e4c275
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 20:30 UTC

fix(web): clear stale chat action shortcuts (#15394)

maria committed Oct 3, 2026 at 21:19 UTC 2d81e4c27559bbd78564bc8cc3b38a0011814361
1 file changed +61 -11
apps/web/src/components/ChatView.tsx
+61 -11
@@ -294,7 +294,10 @@ import {
294 import { cn, randomUUID } from "~/lib/utils";
295 import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
296 import { stackedThreadToast, toastManager } from "./ui/toast";
297 -import { decodeProjectScriptKeybindingRule } from "~/lib/projectScriptKeybindings";
297 +import {
298 + decodeProjectScriptKeybindingRule,
299 + keybindingValueForCommand,
300 +} from "~/lib/projectScriptKeybindings";
301 import { type NewProjectScriptInput } from "./ProjectScriptsControl";
302 import {
303 buildProjectScript,
@@ -1534,6 +1537,9 @@ export default function ChatView(props: ChatViewProps) {
1537 const upsertKeybinding = useAtomCommand(serverEnvironment.upsertKeybinding, {
1538 reportFailure: false,
1539 });
1540 + const removeKeybinding = useAtomCommand(serverEnvironment.removeKeybinding, {
1541 + reportFailure: false,
1542 + });
1543 const openTerminal = useAtomCommand(terminalEnvironment.open, "terminal open");
1544 const writeTerminal = useAtomCommand(terminalEnvironment.write, "terminal write");
1545 const closeTerminalMutation = useAtomCommand(terminalEnvironment.close, "terminal close");
@@ -4940,20 +4946,64 @@ export default function ChatView(props: ChatViewProps) {
4946 command: input.keybindingCommand,
4947 });
4948
4943 - if (isElectron && keybindingRule) {
4944 - return mapAtomCommandResult(
4945 - await upsertKeybinding({
4946 - environmentId,
4947 - input: keybindingRule,
4948 - }),
4949 - () => undefined,
4950 - );
4949 + if (!isElectron) return updateResult;
4950 +
4951 + const scriptId = input.keybindingCommand
4952 + ? projectScriptIdFromCommand(input.keybindingCommand)
4953 + : null;
4954 + if (!keybindingRule && !input.previousScripts.some((script) => script.id === scriptId)) {
4955 + return updateResult;
4956 }
4952 - return updateResult;
4957 + const retainedElsewhere =
4958 + !input.nextScripts.some((script) => script.id === scriptId) &&
4959 + (settings.defaultProjectScripts.some((script) => script.id === scriptId) ||
4960 + Object.entries(settings.projectSettingsOverrides).some(
4961 + ([projectId, entry]) =>
4962 + projectId !== input.projectId &&
4963 + entry.defaultProjectScripts?.some((script) => script.id === scriptId),
4964 + ) ||
4965 + allProjects.some(
4966 + (other) =>
4967 + other.environmentId === environmentId &&
4968 + other.id !== input.projectId &&
4969 + resolveProjectScripts(settings, other).some((script) => script.id === scriptId),
4970 + ));
4971 + if (!keybindingRule && retainedElsewhere) return updateResult;
4972 +
4973 + const previousRules = (
4974 + environmentById.get(environmentId)?.serverConfig?.keybindings ?? []
4975 + ).flatMap((binding) => {
4976 + if (binding.command !== input.keybindingCommand || binding.whenAst) return [];
4977 + const previous = decodeProjectScriptKeybindingRule({
4978 + keybinding: keybindingValueForCommand([binding], input.keybindingCommand),
4979 + command: input.keybindingCommand,
4980 + });
4981 + return previous ? [previous] : [];
4982 + });
4983 + const previous = previousRules.at(-1);
4984 + for (const rule of keybindingRule ? previousRules.slice(0, -1) : previousRules) {
4985 + const result = await removeKeybinding({ environmentId, input: rule });
4986 + if (result._tag === "Failure") return mapAtomCommandResult(result, () => undefined);
4987 + }
4988 + return keybindingRule
4989 + ? mapAtomCommandResult(
4990 + await upsertKeybinding({
4991 + environmentId,
4992 + input:
4993 + previous && previous.key !== keybindingRule.key
4994 + ? { ...keybindingRule, replace: previous }
4995 + : keybindingRule,
4996 + }),
4997 + () => undefined,
4998 + )
4999 + : updateResult;
5000 },
5001 [
5002 + allProjects,
5003 + environmentById,
5004 environmentId,
4956 - settings.projectSettingsOverrides,
5005 + removeKeybinding,
5006 + settings,
5007 supportsProjectSettingsOverrides,
5008 updateProjectScriptSettings,
5009 upsertKeybinding,