From b961dfd999f52880920cee4618926960b73be2e0 Mon Sep 17 00:00:00 2001 From: Yun Chan Date: Tue, 20 Oct 2026 22:49:11 +0900 Subject: [PATCH] fix(commands): decide whether a deleted command was in use when the delete commits, not when it was clicked Picking another command during the undo window was overwritten with 'raw' five seconds later because the selection was captured at click time. --- apps/desktop/src/renderer/pages/CommandsPage.tsx | 9 ++++++--- apps/desktop/src/renderer/pages/tools/tools-model.ts | 11 +++++++++++ apps/desktop/tests/unit/renderer-tools-model.test.ts | 11 +++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/renderer/pages/CommandsPage.tsx b/apps/desktop/src/renderer/pages/CommandsPage.tsx index 8ca9522..55cc17a 100644 --- a/apps/desktop/src/renderer/pages/CommandsPage.tsx +++ b/apps/desktop/src/renderer/pages/CommandsPage.tsx @@ -35,6 +35,7 @@ import { COMMAND_NONE, commandSelection, commandTestRequest, + isInstructionInUse, llmActionLabelKey, resolveCommandPipeline, withoutHidden, @@ -180,15 +181,17 @@ export function CommandsPage(): React.ReactElement { // 한 건 삭제는 확인 대신 "삭제했습니다 · 되돌리기" — 알림이 닫힐 때 실제로 지운다. const handleDelete = (inst: CustomInstruction) => { - const wasSelected = config?.defaultLLMAction === 'custom' && config.activeInstructionId === inst.id remove({ id: inst.id, message: t('tools.commands.deleted', { name: inst.name }), commit: async () => { const res = await window.electronAPI.instruction.delete({ id: inst.id }) if (!res.success) return false - // 쓰던 명령을 지웠으면 원문 그대로 넣기로 돌린다(예전 동작 유지) - if (wasSelected) await window.electronAPI.config.set({ key: 'defaultLLMAction', value: 'none' }) + // 지금도 쓰이는 명령을 지웠으면 원문 그대로 넣기로 돌린다 — 확정 시점의 설정으로 판단한다 + const latest = await window.electronAPI.config.getAll() + if (latest.success && isInstructionInUse(latest.data, inst.id)) { + await window.electronAPI.config.set({ key: 'defaultLLMAction', value: 'none' }) + } return true }, onCommitted: () => void loadData(), diff --git a/apps/desktop/src/renderer/pages/tools/tools-model.ts b/apps/desktop/src/renderer/pages/tools/tools-model.ts index 59c2b09..af9642a 100644 --- a/apps/desktop/src/renderer/pages/tools/tools-model.ts +++ b/apps/desktop/src/renderer/pages/tools/tools-model.ts @@ -55,6 +55,17 @@ export function commandSelection(pipeline: CommandPip return '' } +/** + * 지운 명령이 지금도 받아쓰기에 쓰이는가 — 삭제 확정(되돌리기 알림이 닫힐 때) 시점의 설정으로 판단한다. + * 삭제를 누른 순간 값으로 판단하면, 그사이 사용자가 고른 다른 명령을 '원문 그대로'로 덮었다. + */ +export function isInstructionInUse( + config: { defaultLLMAction?: unknown; activeInstructionId?: unknown } | null | undefined, + instructionId: string, +): boolean { + return config?.defaultLLMAction === 'custom' && config.activeInstructionId === instructionId +} + /** 일반 후처리 액션 이름 */ export function llmActionLabelKey(action: Exclude): TranslationKey { switch (action) { diff --git a/apps/desktop/tests/unit/renderer-tools-model.test.ts b/apps/desktop/tests/unit/renderer-tools-model.test.ts index 43858bf..ecfd538 100644 --- a/apps/desktop/tests/unit/renderer-tools-model.test.ts +++ b/apps/desktop/tests/unit/renderer-tools-model.test.ts @@ -15,6 +15,7 @@ import { llmActionLabelKey, resolveCommandPipeline, withoutHidden, + isInstructionInUse, } from '../../src/renderer/pages/tools/tools-model' const polish = { id: 'i1', name: '정중하게', prompt: '{{text}} 를 정중하게' } @@ -95,3 +96,13 @@ describe('withoutHidden / documentIndexLabelKey', () => { expect(documentIndexLabelKey({ id: 'd', indexed: true }, null)).toBe('rag.indexed') }) }) + +describe('isInstructionInUse — 명령 삭제 확정 시점의 설정으로 판단', () => { + it('지운 명령이 아직 선택돼 있을 때만 true', () => { + expect(isInstructionInUse({ defaultLLMAction: 'custom', activeInstructionId: 'x' }, 'x')).toBe(true) + // 되돌리기 알림 동안 다른 명령을 골랐다 — 덮으면 안 된다 + expect(isInstructionInUse({ defaultLLMAction: 'custom', activeInstructionId: 'y' }, 'x')).toBe(false) + expect(isInstructionInUse({ defaultLLMAction: 'refine', activeInstructionId: 'x' }, 'x')).toBe(false) + expect(isInstructionInUse(null, 'x')).toBe(false) + }) +})