mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-09 16:02:36 +01:00
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>
24 lines
992 B
TypeScript
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";
|
|
}
|