Skip to content

Commit

Permalink
fix: execute pending command with delay.
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes committed Dec 23, 2024
1 parent 797768a commit 7da4e5c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
7 changes: 6 additions & 1 deletion ee/tabby-ui/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 1 addition & 4 deletions ee/tabby-ui/app/files/components/chat-side-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ export const ChatSideBar: React.FC<ChatSideBarProps> = ({
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()
}
Expand Down
6 changes: 5 additions & 1 deletion ee/tabby-ui/components/chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
9 changes: 1 addition & 8 deletions ee/tabby-ui/components/chat/question-answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7da4e5c

Please sign in to comment.