Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(desktop): 队列仅一条时输入框内 Cmd/Ctrl+Enter 直接插话该条

DavidShen56a44ef23ceb
diff --git a/apps/desktop/src/renderer/__tests__/pendingQueueRowPresentation.test.ts b/apps/desktop/src/renderer/__tests__/pendingQueueRowPresentation.test.ts
index 52973ad11f..0894a45382 100644
--- a/apps/desktop/src/renderer/__tests__/pendingQueueRowPresentation.test.ts
+++ b/apps/desktop/src/renderer/__tests__/pendingQueueRowPresentation.test.ts
@@ -7,6 +7,7 @@ import {
import {
getPendingQueueRowPresentation,
resolvePendingQueueEditSubmission,
+ resolveSoleSteerableQueuedMessage,
} from '@/components/new-chat/pendingQueueRowPresentation';
import type { QueuedMessage } from '@/lib/makerChatStore';
@@ -292,3 +293,41 @@ describe('getPendingQueueRowPresentation', () => {
}
});
});
+
+describe('resolveSoleSteerableQueuedMessage', () => {
+ const idle = { editingClientId: null, steeringClientIds: [] as string[] };
+
+ it('targets the only queued row so the composer shortcut can steer it', () => {
+ expect(resolveSoleSteerableQueuedMessage([queuedMessage()], idle)).toBe('client-1');
+ });
+
+ it('declines when the target is ambiguous or the row cannot steer right now', () => {
+ expect(
+ resolveSoleSteerableQueuedMessage(
+ [queuedMessage(), queuedMessage({ clientId: 'client-2' })],
+ idle,
+ ),
+ ).toBeNull();
+ expect(
+ resolveSoleSteerableQueuedMessage([queuedMessage({ isPendingEnqueue: true })], idle),
+ ).toBeNull();
+ expect(
+ resolveSoleSteerableQueuedMessage(
+ [queuedMessage({ sourcePlugin: { pluginId: 'ghost-github' } })],
+ idle,
+ ),
+ ).toBeNull();
+ expect(
+ resolveSoleSteerableQueuedMessage([queuedMessage()], {
+ editingClientId: 'client-1',
+ steeringClientIds: [],
+ }),
+ ).toBeNull();
+ expect(
+ resolveSoleSteerableQueuedMessage([queuedMessage()], {
+ editingClientId: null,
+ steeringClientIds: ['client-1'],
+ }),
+ ).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index 16529034e1..fba612ea0f 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -188,6 +188,7 @@ import {
shouldPreservePlanModeComposerDraft,
} from './planModeComposerCommand';
import { PendingQueuePanel } from './PendingQueuePanel';
+import { resolveSoleSteerableQueuedMessage } from './pendingQueueRowPresentation';
import { SendButton } from './SendButton';
import { FolderPickerPopover, addRecentFolder } from './FolderPickerPopover';
import { SlashCommandPalette } from './SlashCommandPalette';
@@ -1487,6 +1488,9 @@ export function ChatInput({
onQueueExpandedChangeRef.current = onQueueExpandedChange;
const queueEditingClientIdRef = useRef(queueEditingClientId);
queueEditingClientIdRef.current = queueEditingClientId;
+ // 空输入框 + 队列仅一条时,输入框里的 Cmd/Ctrl+Enter 直接插话这条(稳定的 window
+ // capture 监听经 ref 读当前值;赋值在 handleQueueSteer 之后)。
+ const steerSoleQueuedMessageRef = useRef<() => boolean>(() => false);
const onQueueEditCancelRef = useRef(onQueueEditCancel);
onQueueEditCancelRef.current = onQueueEditCancel;
const queueEditCancelAllowedRef = useRef(true);
@@ -3484,6 +3488,7 @@ export function ChatInput({
event.preventDefault();
event.stopPropagation();
if (panelBridgeRef.current?.captureKey(event)) return;
+ if (steerSoleQueuedMessageRef.current()) return;
clearPressTimer();
voiceShortcutPressRef.current = null;
void voiceInputStopAndSendRef.current(enterIntent);
@@ -6089,6 +6094,19 @@ export function ChatInput({
},
[onQueueSteer],
);
+ steerSoleQueuedMessageRef.current = () => {
+ // 输入框里有任何待发内容(正文、附件、评论、语音稿)时快捷键仍发送输入框本身。
+ if (!onQueueSteer || voiceBusyOnCurrentComposer || !composerFullyEmptyRef.current()) {
+ return false;
+ }
+ const clientId = resolveSoleSteerableQueuedMessage(pendingQueue ?? [], {
+ editingClientId: queueEditingClientId,
+ steeringClientIds: steeringQueueClientIds,
+ });
+ if (!clientId) return false;
+ void handleQueueSteer(clientId);
+ return true;
+ };
const queueEditActive = Boolean(queueEditingClientId && onQueueEditSubmit);
const submitQueueEdit = useCallback(async () => {
diff --git a/apps/desktop/src/renderer/components/new-chat/pendingQueueRowPresentation.ts b/apps/desktop/src/renderer/components/new-chat/pendingQueueRowPresentation.ts
index b831dd031a..eb62f1cdf9 100644
--- a/apps/desktop/src/renderer/components/new-chat/pendingQueueRowPresentation.ts
+++ b/apps/desktop/src/renderer/components/new-chat/pendingQueueRowPresentation.ts
@@ -105,6 +105,22 @@ export function getPendingQueueRowPresentation(entry: QueuedMessage): PendingQue
};
}
+/**
+ * 空输入框里按 Cmd/Ctrl+Enter 时可直接插话的队列条目:仅当队列恰好一条且该行此刻
+ * 能插话(与行内 ⬆️ 同一判据)时返回其 clientId。多条时无法判断用户指哪条,返回 null,
+ * 仍需把焦点放到具体行上再按快捷键。
+ */
+export function resolveSoleSteerableQueuedMessage(
+ queue: readonly QueuedMessage[],
+ state: { editingClientId: string | null; steeringClientIds: readonly string[] },
+): string | null {
+ if (queue.length !== 1 || state.editingClientId !== null) return null;
+ const [entry] = queue;
+ if (!entry || !getPendingQueueRowPresentation(entry).canSteer) return null;
+ if (state.steeringClientIds.includes(entry.clientId)) return null;
+ return entry.clientId;
+}
+
/**
* Keep an untouched encoded quote body byte-for-byte stable. The queue editor
* shows the markerless projection, so submitting that projection as a rewrite