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.
This commit is contained in:
parent
ce8d603b4a
commit
b961dfd999
3 changed files with 28 additions and 3 deletions
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -55,6 +55,17 @@ export function commandSelection<T extends InstructionLike>(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<LLMAction, 'custom'>): TranslationKey {
|
||||
switch (action) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue