Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(chat): scope Cmd+Enter build shortcut to plan mode (#16703)

Vasco Schiavo8780efb3cd69
diff --git a/__tests__/components/chat/chat-interface.test.tsx b/__tests__/components/chat/chat-interface.test.tsx
index 0a227e0f8a..b1bace7804 100644
--- a/__tests__/components/chat/chat-interface.test.tsx
+++ b/__tests__/components/chat/chat-interface.test.tsx
@@ -1033,3 +1033,112 @@ describe("ChatInterface - Tracking", () => {
expect(trackInitialQuerySubmittedMock).not.toHaveBeenCalled();
});
});
+
+describe("ChatInterface - Build plan keyboard shortcut", () => {
+ let queryClient: QueryClient;
+
+ const BUILD_PROMPT =
+ "Execute the plan based on the .agents_tmp/PLAN.md file.";
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ mockSend.mockResolvedValue({ queued: false });
+ queryClient = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ useOptimisticUserMessageStore.setState({ pendingMessages: [] });
+ useErrorMessageStore.setState({ errorMessage: null });
+ (useConfig as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
+ data: {},
+ });
+ (
+ useUnifiedUploadFiles as unknown as ReturnType<typeof vi.fn>
+ ).mockReturnValue({
+ mutateAsync: vi
+ .fn()
+ .mockResolvedValue({ skipped_files: [], uploaded_files: [] }),
+ isLoading: false,
+ });
+ useEventStore.setState({ events: [], eventIds: new Set(), uiEvents: [] });
+ });
+
+ function renderInterface() {
+ render(
+ <QueryClientProvider client={queryClient}>
+ <MemoryRouter initialEntries={["/test-conversation-id"]}>
+ <Routes>
+ <Route path=":conversationId" element={<ChatInterface />} />
+ </Routes>
+ </MemoryRouter>
+ </QueryClientProvider>,
+ );
+ }
+
+ const pressBuildShortcut = () => {
+ fireEvent.keyDown(document, { key: "Enter", metaKey: true });
+ fireEvent.keyDown(document, { key: "Enter", ctrlKey: true });
+ };
+
+ const sentBuildPrompt = () =>
+ mockSend.mock.calls.some(([message]) =>
+ JSON.stringify(message).includes(BUILD_PROMPT),
+ );
+
+ it("does not send the build prompt in code mode", () => {
+ act(() => {
+ useConversationStore.setState({
+ conversationMode: "code",
+ planContent: null,
+ });
+ });
+
+ renderInterface();
+ pressBuildShortcut();
+
+ expect(sentBuildPrompt()).toBe(false);
+ });
+
+ it("does not send the build prompt in code mode when a plan exists", () => {
+ act(() => {
+ useConversationStore.setState({
+ conversationMode: "code",
+ planContent: "# Plan\n\n- step one",
+ });
+ });
+
+ renderInterface();
+ pressBuildShortcut();
+
+ expect(sentBuildPrompt()).toBe(false);
+ });
+
+ it("does not send the build prompt in plan mode when no plan exists", () => {
+ act(() => {
+ useConversationStore.setState({
+ conversationMode: "plan",
+ planContent: null,
+ });
+ });
+
+ renderInterface();
+ pressBuildShortcut();
+
+ expect(sentBuildPrompt()).toBe(false);
+ });
+
+ it("sends the build prompt in plan mode when a plan exists", async () => {
+ act(() => {
+ useConversationStore.setState({
+ conversationMode: "plan",
+ planContent: "# Plan\n\n- step one",
+ });
+ });
+
+ renderInterface();
+ fireEvent.keyDown(document, { key: "Enter", metaKey: true });
+
+ await waitFor(() => {
+ expect(sentBuildPrompt()).toBe(true);
+ });
+ });
+});
diff --git a/src/components/features/chat/chat-interface.tsx b/src/components/features/chat/chat-interface.tsx
index 5521222962..a4f2e9a32b 100644
--- a/src/components/features/chat/chat-interface.tsx
+++ b/src/components/features/chat/chat-interface.tsx
@@ -63,7 +63,8 @@ function getEntryPoint(
export function ChatInterface() {
const { trackInitialQuerySubmitted, trackUserMessageSent } = useTracking();
- const { setMessageToSend } = useConversationStore();
+ const { setMessageToSend, conversationMode, planContent } =
+ useConversationStore();
const {
errorMessage,
errorCode,
@@ -133,9 +134,11 @@ export function ChatInterface() {
// Global keyboard shortcut for Build button (Cmd+Enter / Ctrl+Enter)
// This is placed here instead of PlanPreview to avoid duplicate listeners
- // when multiple PlanPreview components exist in the chat
+ // when multiple PlanPreview components exist in the chat.
+ // Gated on the same conditions as the Build button (ConversationTabs'
+ // `isBuildDisabled`) so it cannot fire outside the plan flow.
React.useEffect(() => {
- if (isAgentRunning) {
+ if (isAgentRunning || conversationMode !== "plan" || !planContent) {
return undefined;
}
@@ -154,7 +157,13 @@ export function ChatInterface() {
return () => {
document.removeEventListener("keydown", handleKeyDown);
};
- }, [isAgentRunning, handleBuildPlanClick, scrollDomToBottom]);
+ }, [
+ isAgentRunning,
+ conversationMode,
+ planContent,
+ handleBuildPlanClick,
+ scrollDomToBottom,
+ ]);
const { selectedRepository, replayJson } = useInitialQueryStore();
const { conversationId } = useOptionalConversationId();