Files
PaperClipAI/ui/src/hooks/useComposerSubmitKey.ts
T
DottaandPaperclip b400f76647 feat(ui): submit task composers with Enter by default (#19272)
Use Enter to submit task replies and new tasks, with Shift+Enter for a new line. Add an experimental preference to require Command/Ctrl+Enter.

Preserve autocomplete selection and IME confirmation, and retain the modifier shortcut until saved settings load.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-11-05 11:40:18 -06:00

24 lines
992 B
TypeScript

import { useContext } from "react";
import { QueryClient, QueryClientContext, useQuery } from "@tanstack/react-query";
import { instanceSettingsApi } from "@/api/instanceSettings";
import { queryKeys } from "@/lib/queryKeys";
let detachedClient: QueryClient | null = null;
/** Shared task-composer preference, including isolated previews without a query provider. */
export function useComposerSubmitKey(): "enter" | "mod-enter" {
const contextClient = useContext(QueryClientContext);
if (!contextClient) detachedClient ??= new QueryClient();
const { data } = useQuery(
{
queryKey: queryKeys.instance.experimentalSettings,
queryFn: () => instanceSettingsApi.getExperimental(),
enabled: contextClient != null,
},
contextClient ?? detachedClient!,
);
if (!contextClient) return "enter";
// Keep plain Enter safe until the saved preference is known on a cold load.
return !data || data.enableLegacyComposerSubmit === true ? "mod-enter" : "enter";
}