mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-17 04:36:57 +00:00
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { CommandGroup, CommandItem, CommandSeparator } from "../ui/command";
|
|
import { useEditor } from "novel";
|
|
import { Check, TextQuote, TrashIcon } from "lucide-react";
|
|
|
|
const AICompletionCommands = ({
|
|
completion,
|
|
onDiscard,
|
|
}: {
|
|
completion: string;
|
|
onDiscard: () => void;
|
|
}) => {
|
|
const { editor } = useEditor();
|
|
return (
|
|
<>
|
|
<CommandGroup>
|
|
<CommandItem
|
|
className="gap-2 px-4"
|
|
value="replace"
|
|
onSelect={() => {
|
|
const selection = editor.view.state.selection;
|
|
|
|
editor
|
|
.chain()
|
|
.focus()
|
|
.insertContentAt(
|
|
{
|
|
from: selection.from,
|
|
to: selection.to,
|
|
},
|
|
completion,
|
|
)
|
|
.run();
|
|
}}
|
|
>
|
|
<Check className="h-4 w-4 text-muted-foreground" />
|
|
Replace selection
|
|
</CommandItem>
|
|
<CommandItem
|
|
className="gap-2 px-4"
|
|
value="insert"
|
|
onSelect={() => {
|
|
const selection = editor.view.state.selection;
|
|
editor
|
|
.chain()
|
|
.focus()
|
|
.insertContentAt(selection.to + 1, completion)
|
|
.run();
|
|
}}
|
|
>
|
|
<TextQuote className="h-4 w-4 text-muted-foreground" />
|
|
Insert below
|
|
</CommandItem>
|
|
</CommandGroup>
|
|
<CommandSeparator />
|
|
|
|
<CommandGroup>
|
|
<CommandItem onSelect={onDiscard} value="thrash" className="gap-2 px-4">
|
|
<TrashIcon className="h-4 w-4 text-muted-foreground" />
|
|
Discard
|
|
</CommandItem>
|
|
</CommandGroup>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default AICompletionCommands;
|