From 4b848cca1a2492b773b77f5b64e45e5482a04272 Mon Sep 17 00:00:00 2001 From: Jackson Chen <541898146chen@gmail.com> Date: Wed, 11 Sep 2024 02:08:51 -0500 Subject: [PATCH] to: smart apply in editor also pass language id a --- clients/tabby-chat-panel/src/index.ts | 3 ++- ee/tabby-ui/components/chat/chat.tsx | 4 ++-- ee/tabby-ui/components/message-markdown/index.tsx | 4 +++- ee/tabby-ui/components/ui/codeblock.tsx | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clients/tabby-chat-panel/src/index.ts b/clients/tabby-chat-panel/src/index.ts index 28af36a7e63e..e7c504154fb7 100644 --- a/clients/tabby-chat-panel/src/index.ts +++ b/clients/tabby-chat-panel/src/index.ts @@ -51,7 +51,7 @@ export interface ClientApi { onApplyInEditor: (content: string) => void // smart apply into editor - onSmartApplyInEditor: (content: string) => void + onSmartApplyInEditor: (languageId: string, content: string) => void // On current page is loaded. onLoaded: () => void @@ -82,6 +82,7 @@ export function createClient(target: HTMLIFrameElement, api: ClientApi): ServerA onApplyInEditor: api.onApplyInEditor, onLoaded: api.onLoaded, onCopy: api.onCopy, + onSmartApplyInEditor: api.onSmartApplyInEditor, }, }) } diff --git a/ee/tabby-ui/components/chat/chat.tsx b/ee/tabby-ui/components/chat/chat.tsx index ccc4da3cb178..7c832a6afdc6 100644 --- a/ee/tabby-ui/components/chat/chat.tsx +++ b/ee/tabby-ui/components/chat/chat.tsx @@ -40,7 +40,7 @@ type ChatContextValue = { container?: HTMLDivElement onCopyContent?: (value: string) => void onApplyInEditor?: (value: string) => void - onSmartApplyInEditor?: (value: string) => void + onSmartApplyInEditor?: (languageId: string, value: string) => void relevantContext: Context[] removeRelevantContext: (index: number) => void } @@ -73,7 +73,7 @@ interface ChatProps extends React.ComponentProps<'div'> { onCopyContent?: (value: string) => void onSubmitMessage?: (msg: string, relevantContext?: Context[]) => Promise onApplyInEditor?: (value: string) => void - onSmartApplyInEditor?: (value: string) => void + onSmartApplyInEditor?: (languageId: string, value: string) => void } function ChatRenderer( diff --git a/ee/tabby-ui/components/message-markdown/index.tsx b/ee/tabby-ui/components/message-markdown/index.tsx index 79f02e383a2b..49e4b5e87757 100644 --- a/ee/tabby-ui/components/message-markdown/index.tsx +++ b/ee/tabby-ui/components/message-markdown/index.tsx @@ -65,7 +65,9 @@ export interface MessageMarkdownProps { attachmentCode?: Maybe> onCopyContent?: ((value: string) => void) | undefined onApplyInEditor?: ((value: string) => void) | undefined - onSmartApplyInEditor?: ((value: string) => void) | undefined + onSmartApplyInEditor?: + | ((languageId: string, value: string) => void) + | undefined onCodeCitationClick?: (code: MessageAttachmentCode) => void onCodeCitationMouseEnter?: (index: number) => void onCodeCitationMouseLeave?: (index: number) => void diff --git a/ee/tabby-ui/components/ui/codeblock.tsx b/ee/tabby-ui/components/ui/codeblock.tsx index 17aa13d6df71..d4e06d07d217 100644 --- a/ee/tabby-ui/components/ui/codeblock.tsx +++ b/ee/tabby-ui/components/ui/codeblock.tsx @@ -26,7 +26,7 @@ interface Props { value: string onCopyContent?: (value: string) => void onApplyInEditor?: (value: string) => void - onSmartApplyInEditor?: (value: string) => void + onSmartApplyInEditor?: (languageId: string, value: string) => void } interface languageMap { @@ -102,7 +102,7 @@ const CodeBlock: FC = memo( variant="ghost" size="icon" className="text-xs hover:bg-[#3C382F] hover:text-[#F4F4F5] focus-visible:ring-1 focus-visible:ring-slate-700 focus-visible:ring-offset-0" - onClick={() => onSmartApplyInEditor(value)} + onClick={() => onSmartApplyInEditor(language, value)} > Smart Apply in Editor