From 7da4e5c12b63d9739d0bb064e55561a3e5573233 Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Mon, 23 Dec 2024 23:41:04 +0800 Subject: [PATCH] fix: execute pending command with delay. --- ee/tabby-ui/app/chat/page.tsx | 7 ++++++- ee/tabby-ui/app/files/components/chat-side-bar.tsx | 5 +---- ee/tabby-ui/components/chat/chat.tsx | 6 +++++- ee/tabby-ui/components/chat/question-answer.tsx | 9 +-------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ee/tabby-ui/app/chat/page.tsx b/ee/tabby-ui/app/chat/page.tsx index ff2278e6910a..b6eb21b629e5 100644 --- a/ee/tabby-ui/app/chat/page.tsx +++ b/ee/tabby-ui/app/chat/page.tsx @@ -278,9 +278,14 @@ export default function ChatPage() { pendingRelevantContexts.forEach(context => { currentChatRef.addRelevantContext(context) }) + currentChatRef.updateActiveSelection(pendingActiveSelection) + if (pendingCommand) { - currentChatRef.executeCommand(pendingCommand) + // FIXME: this delay is a workaround for waiting for the active selection to be updated + setTimeout(() => { + currentChatRef.executeCommand(pendingCommand) + }, 500) } clearPendingState() diff --git a/ee/tabby-ui/app/files/components/chat-side-bar.tsx b/ee/tabby-ui/app/files/components/chat-side-bar.tsx index a0cfedf8e907..e96d1c23f3c5 100644 --- a/ee/tabby-ui/app/files/components/chat-side-bar.tsx +++ b/ee/tabby-ui/app/files/components/chat-side-bar.tsx @@ -119,10 +119,7 @@ export const ChatSideBar: React.FC = ({ gitUrl } }) - // FIXME: this delay is a workaround for waiting for the active selection to be updated - setTimeout(() => { - client.executeCommand(getCommand(pendingEvent)) - }, 100) + client.executeCommand(getCommand(pendingEvent)) } execute() } diff --git a/ee/tabby-ui/components/chat/chat.tsx b/ee/tabby-ui/components/chat/chat.tsx index 805cb7abeb40..00afeb5718c2 100644 --- a/ee/tabby-ui/components/chat/chat.tsx +++ b/ee/tabby-ui/components/chat/chat.tsx @@ -487,12 +487,16 @@ function ChatRenderer( return handleSendUserChat.current?.(userMessage) } - const executeCommand = async (command: ChatCommand) => { + const handleExecuteCommand = useLatest(async (command: ChatCommand) => { const prompt = getPromptForChatCommand(command) sendUserChat({ message: prompt, selectContext: activeSelection ?? undefined }) + }) + + const executeCommand = async (command: ChatCommand) => { + return handleExecuteCommand.current?.(command) } const handleSubmit = async (value: string) => { diff --git a/ee/tabby-ui/components/chat/question-answer.tsx b/ee/tabby-ui/components/chat/question-answer.tsx index 9e69a2ad61a3..bab877145ac2 100644 --- a/ee/tabby-ui/components/chat/question-answer.tsx +++ b/ee/tabby-ui/components/chat/question-answer.tsx @@ -344,14 +344,7 @@ function AssistantMessageCard(props: AssistantMessageCardProps) { // and will navigate to target without opening a new tab. // So we use `openInEditor` here. if (isClient || !isInEditor) { - openInEditor({ - filepath: { - kind: 'git', - filepath: context.filepath, - gitUrl: context.git_url - }, - location: context.range - }) + openInEditor(getFileLocationFromContext(context)) } else { const url = buildCodeBrowserUrlForContext(window.location.href, context) openExternal(url)