/* Copyright 2026 Marimo. All rights reserved. */ import { PlayIcon } from "lucide-react"; import React from "react"; import { MinimalHotkeys } from "@/components/shortcuts/renderShortcut"; import { Button } from "@/components/ui/button"; import { Tooltip } from "@/components/ui/tooltip"; import { isPlatformMac } from "@/core/hotkeys/shortcuts"; /** * Common keyboard shortcut handlers for AI completions */ export const createAiCompletionOnKeydown = (opts: { handleAcceptCompletion: () => void; handleDeclineCompletion: () => void; isLoading: boolean; hasCompletion: boolean; }) => { const { handleAcceptCompletion, handleDeclineCompletion, isLoading, hasCompletion, } = opts; return (e: React.KeyboardEvent) => { const metaKey = isPlatformMac() ? e.metaKey : e.ctrlKey; // Mod+Enter should accept the completion, if there is one if (metaKey && e.key === "Enter" && !isLoading && hasCompletion) { handleAcceptCompletion(); } // Mod+Shift+Delete should decline the completion const deleteKey = e.key === "Delete" || e.key === "Backspace"; if (deleteKey && metaKey && e.shiftKey) { handleDeclineCompletion(); e.preventDefault(); e.stopPropagation(); } }; }; export const CompletionActionsCellFooter: React.FC<{ isLoading: boolean; onAccept: () => void; onDecline: () => void; size?: "xs" | "sm"; multipleCompletions?: boolean; runCell?: () => void; }> = ({ isLoading, onAccept, onDecline, runCell }) => { return ( <> ); }; export const AcceptCompletionButton: React.FC<{ isLoading: boolean; onAccept: () => void; multipleCompletions?: boolean; size?: "xs" | "sm"; buttonStyles?: string; playButtonStyles?: string; borderless?: boolean; acceptShortcut?: string; runCell?: () => void; }> = ({ isLoading, onAccept, multipleCompletions = false, size = "sm", buttonStyles, acceptShortcut, runCell, playButtonStyles, borderless = false, }) => { const handleAcceptAndRun = () => { onAccept(); if (runCell) { runCell(); } }; const text = multipleCompletions ? "Accept all" : "Accept"; const baseClasses = `h-6 text-(--grass-11) bg-(--grass-3)/60 hover:bg-(--grass-3) dark:bg-(--grass-4)/80 dark:hover:bg-(--grass-3) font-semibold active:bg-(--grass-5) dark:active:bg-(--grass-4) border-(--green-6) border hover:shadow-xs`; if (runCell) { return (
); } return ( ); }; export const RejectCompletionButton: React.FC<{ onDecline: () => void; multipleCompletions?: boolean; size?: "xs" | "sm"; className?: string; borderless?: boolean; declineShortcut?: string; }> = ({ onDecline, multipleCompletions = false, size = "sm", className, declineShortcut, borderless = false, }) => { return ( ); };