From 6309d9b3bf282536c6ee2c37c9ff56973d813871 Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Tue, 6 May 2025 10:12:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86=E4=B8=8E=E5=88=97=E8=A1=A8=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=EF=BC=8C=E7=9B=B4=E6=8E=A5=E5=9B=9E=E8=BD=A6=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=80=89=E4=B8=AD=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 允许直接按回车键执行列表中的选中项,取代原有的 Alt+Enter 快捷键 --- .../src/components/CommandInputBar.vue | 78 +++++++++++-------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/packages/frontend/src/components/CommandInputBar.vue b/packages/frontend/src/components/CommandInputBar.vue index 11e4ae0..9b41397 100644 --- a/packages/frontend/src/components/CommandInputBar.vue +++ b/packages/frontend/src/components/CommandInputBar.vue @@ -128,6 +128,40 @@ const commandInputRef = ref(null); // Ref for command i // Removed debug computed property const handleCommandInputKeydown = (event: KeyboardEvent) => { + // --- 移动到外部:优先处理 Enter 键执行选中项 --- + if (!event.altKey && event.key === 'Enter') { + const target = commandInputSyncTarget.value; + let selectedCommand: string | undefined; + let resetSelection: (() => void) | undefined; + + if (target === 'quickCommands' && quickCommandsSelectedIndex.value >= 0) { + const commands = quickCommandsFiltered.value; + if (quickCommandsSelectedIndex.value < commands.length) { + selectedCommand = commands[quickCommandsSelectedIndex.value].command; + resetSelection = resetQuickCommandsSelection; + } + } else if (target === 'commandHistory' && historySelectedIndex.value >= 0) { + const history = historyFiltered.value; + if (historySelectedIndex.value < history.length) { + selectedCommand = history[historySelectedIndex.value].command; + resetSelection = resetHistorySelection; + } + } + + if (selectedCommand !== undefined) { + event.preventDefault(); + console.log(`[CommandInputBar] Enter detected with selection. Sending selected command: ${selectedCommand}`); + emit('send-command', selectedCommand); // 发送选中命令 (移除多余的 \n) + if (activeSessionId.value) { + updateSessionCommandInput(activeSessionId.value, ''); // 清空输入框 + } + resetSelection?.(); // 重置列表选中状态 + return; // 阻止后续的 Enter 处理 + } + // 如果没有选中项,则继续执行下面的默认 Enter 逻辑 + } + // --- 结束:优先处理 Enter 键执行选中项 --- + if (event.ctrlKey && event.key === 'f') { event.preventDefault(); // 阻止浏览器默认的查找行为 isSearching.value = true; @@ -152,45 +186,27 @@ const handleCommandInputKeydown = (event: KeyboardEvent) => { event.preventDefault(); commandHistoryStore.selectNextCommand(); } - } else if (event.altKey && event.key === 'Enter') { - const target = commandInputSyncTarget.value; - let selectedCommand: string | undefined; - - if (target === 'quickCommands') { - const index = quickCommandsSelectedIndex.value; - const commands = quickCommandsFiltered.value; - if (index >= 0 && index < commands.length) { - selectedCommand = commands[index].command; - resetQuickCommandsSelection(); // Reset selection after execution - } - } else if (target === 'commandHistory') { - const index = historySelectedIndex.value; - const history = historyFiltered.value; - if (index >= 0 && index < history.length) { - selectedCommand = history[index].command; - resetHistorySelection(); // Reset selection after execution - } - } - - if (selectedCommand !== undefined) { - event.preventDefault(); - console.log(`[CommandInputBar] Alt+Enter detected. Sending selected command: ${selectedCommand}`); - emit('send-command', selectedCommand + '\n'); - // 清空 store 中的值 - if (activeSessionId.value) { - updateSessionCommandInput(activeSessionId.value, ''); - } - } } else if (event.ctrlKey && event.key === 'c' && currentSessionCommandInput.value === '') { // 检查计算属性的值 // Handle Ctrl+C when input is empty event.preventDefault(); console.log('[CommandInputBar] Ctrl+C detected with empty input. Sending SIGINT.'); emit('send-command', '\x03'); // Send ETX character (Ctrl+C) } else if (!event.altKey && event.key === 'Enter') { - // Handle regular Enter key press - send current input + // Handle regular Enter key press - send current input (empty or not) event.preventDefault(); // Prevent default if needed, e.g., form submission sendCommand(); // Call the existing sendCommand function - } + } else { + // --- 新增:处理其他按键,取消列表选中状态 --- + // 检查按下的键是否是普通输入键或删除键等,而不是导航键或修饰键 + if (!['ArrowUp', 'ArrowDown', 'Enter', 'Shift', 'Control', 'Alt', 'Meta', 'Tab', 'Escape'].includes(event.key)) { + const target = commandInputSyncTarget.value; + if (target === 'quickCommands' && quickCommandsSelectedIndex.value >= 0) { + resetQuickCommandsSelection(); + } else if (target === 'commandHistory' && historySelectedIndex.value >= 0) { + resetHistorySelection(); + } + } + } }; // NEW: Handle blur event on command input