fix: Esc unable to cancel subagent dialog

This commit is contained in:
tanzhenxin
2025-09-16 15:24:58 +08:00
parent 49d7947028
commit 8e2fc76c15
2 changed files with 22 additions and 10 deletions

View File

@@ -5,7 +5,7 @@
*/ */
import { useReducer, useCallback, useMemo } from 'react'; import { useReducer, useCallback, useMemo } from 'react';
import { Box, Text, useInput } from 'ink'; import { Box, Text } from 'ink';
import { wizardReducer, initialWizardState } from '../reducers.js'; import { wizardReducer, initialWizardState } from '../reducers.js';
import { LocationSelector } from './LocationSelector.js'; import { LocationSelector } from './LocationSelector.js';
import { GenerationMethodSelector } from './GenerationMethodSelector.js'; import { GenerationMethodSelector } from './GenerationMethodSelector.js';
@@ -20,6 +20,7 @@ import { Config } from '@qwen-code/qwen-code-core';
import { Colors } from '../../../colors.js'; import { Colors } from '../../../colors.js';
import { theme } from '../../../semantic-colors.js'; import { theme } from '../../../semantic-colors.js';
import { TextEntryStep } from './TextEntryStep.js'; import { TextEntryStep } from './TextEntryStep.js';
import { useKeypress } from '../../../hooks/useKeypress.js';
interface AgentCreationWizardProps { interface AgentCreationWizardProps {
onClose: () => void; onClose: () => void;
@@ -49,8 +50,12 @@ export function AgentCreationWizard({
}, [onClose]); }, [onClose]);
// Centralized ESC key handling for the entire wizard // Centralized ESC key handling for the entire wizard
useInput((input, key) => { useKeypress(
if (key.escape) { (key) => {
if (key.name !== 'escape') {
return;
}
// LLM DescriptionInput handles its own ESC logic when generating // LLM DescriptionInput handles its own ESC logic when generating
const kind = getStepKind(state.generationMethod, state.currentStep); const kind = getStepKind(state.generationMethod, state.currentStep);
if (kind === 'LLM_DESC' && state.isGenerating) { if (kind === 'LLM_DESC' && state.isGenerating) {
@@ -64,8 +69,9 @@ export function AgentCreationWizard({
// On other steps, ESC goes back to previous step // On other steps, ESC goes back to previous step
handlePrevious(); handlePrevious();
} }
} },
}); { isActive: true },
);
const stepProps: WizardStepProps = useMemo( const stepProps: WizardStepProps = useMemo(
() => ({ () => ({

View File

@@ -5,7 +5,7 @@
*/ */
import { useState, useCallback, useMemo, useEffect } from 'react'; import { useState, useCallback, useMemo, useEffect } from 'react';
import { Box, Text, useInput } from 'ink'; import { Box, Text } from 'ink';
import { AgentSelectionStep } from './AgentSelectionStep.js'; import { AgentSelectionStep } from './AgentSelectionStep.js';
import { ActionSelectionStep } from './ActionSelectionStep.js'; import { ActionSelectionStep } from './ActionSelectionStep.js';
import { AgentViewerStep } from './AgentViewerStep.js'; import { AgentViewerStep } from './AgentViewerStep.js';
@@ -18,6 +18,7 @@ import { Colors } from '../../../colors.js';
import { theme } from '../../../semantic-colors.js'; import { theme } from '../../../semantic-colors.js';
import { getColorForDisplay, shouldShowColor } from '../utils.js'; import { getColorForDisplay, shouldShowColor } from '../utils.js';
import { Config, SubagentConfig } from '@qwen-code/qwen-code-core'; import { Config, SubagentConfig } from '@qwen-code/qwen-code-core';
import { useKeypress } from '../../../hooks/useKeypress.js';
interface AgentsManagerDialogProps { interface AgentsManagerDialogProps {
onClose: () => void; onClose: () => void;
@@ -122,8 +123,12 @@ export function AgentsManagerDialog({
); );
// Centralized ESC key handling for the entire dialog // Centralized ESC key handling for the entire dialog
useInput((input, key) => { useKeypress(
if (key.escape) { (key) => {
if (key.name !== 'escape') {
return;
}
const currentStep = getCurrentStep(); const currentStep = getCurrentStep();
if (currentStep === MANAGEMENT_STEPS.AGENT_SELECTION) { if (currentStep === MANAGEMENT_STEPS.AGENT_SELECTION) {
// On first step, ESC cancels the entire dialog // On first step, ESC cancels the entire dialog
@@ -132,8 +137,9 @@ export function AgentsManagerDialog({
// On other steps, ESC goes back to previous step in navigation stack // On other steps, ESC goes back to previous step in navigation stack
handleNavigateBack(); handleNavigateBack();
} }
} },
}); { isActive: true },
);
// Props for child components - now using direct state and callbacks // Props for child components - now using direct state and callbacks
const commonProps = useMemo( const commonProps = useMemo(