feat(commands): multi-select ordered command pipeline with step reordering and single-pass composition (AI-05, AI-07)
This commit is contained in:
parent
f49acf0105
commit
10af20a0ad
157 changed files with 29455 additions and 913 deletions
|
|
@ -12,6 +12,7 @@
|
|||
// IME 상태를 타지 않고 클립보드도 전혀 건드리지 않는다.
|
||||
|
||||
import { getLogger } from '../services/LoggerService'
|
||||
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
|
||||
|
||||
const logger = getLogger('win32-unicode-input')
|
||||
|
||||
|
|
@ -110,9 +111,30 @@ function writeUnicodeKeyPair(buffer: Buffer, pairIndex: number, codeUnit: number
|
|||
buffer.writeUInt32LE(KEYEVENTF_UNICODE | KEYEVENTF_KEYUP, upBase + unionOffset + 4)
|
||||
}
|
||||
|
||||
/** Only zero inserted events are safe to retry through another input backend. */
|
||||
function sendInputBatch(sendInput: SendInputFn, totalEvents: number, buffer: Buffer): boolean {
|
||||
let sent: number
|
||||
try {
|
||||
sent = sendInput(totalEvents, buffer, inputStructSize)
|
||||
} catch (error) {
|
||||
// A native-call exception does not prove that the input stream was untouched.
|
||||
throw new D3ROError(
|
||||
ErrorCode.TextInsertKeySimulationFailed,
|
||||
`SendInput failed with an unknown insertion result; retry blocked: ${error instanceof Error ? error.message : String(error)}`
|
||||
)
|
||||
}
|
||||
if (sent === totalEvents) return true
|
||||
if (sent === 0) return false
|
||||
// Replaying a partially applied batch can delete the user's next word or duplicate text.
|
||||
throw new D3ROError(
|
||||
ErrorCode.TextInsertKeySimulationFailed,
|
||||
`SendInput inserted ${sent}/${totalEvents} events; retry blocked to preserve existing input`
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* UTF-16 문자열을 Windows SendInput(KEYEVENTF_UNICODE) 호출 한 번으로 입력 큐에 넣는다.
|
||||
* 성공 시 true, 지원하지 않거나 실패 시 false 를 반환한다.
|
||||
* 성공 시 true, 미지원 또는 입력 0건이면 false. 일부 입력/결과 불명은 재시도하지 않도록 예외를 던진다.
|
||||
*/
|
||||
export function sendWin32UnicodeText(text: string): boolean {
|
||||
if (!text) return true
|
||||
|
|
@ -128,9 +150,9 @@ export function sendWin32UnicodeText(text: string): boolean {
|
|||
writeUnicodeKeyPair(buffer, i, text.charCodeAt(i))
|
||||
}
|
||||
|
||||
const sent = sendInput(totalEvents, buffer, inputStructSize)
|
||||
return sent === totalEvents
|
||||
return sendInputBatch(sendInput, totalEvents, buffer)
|
||||
} catch (error) {
|
||||
if (error instanceof D3ROError) throw error
|
||||
logger.warn(`SendInput(KEYEVENTF_UNICODE) 실행 실패: ${error instanceof Error ? error.message : String(error)}`)
|
||||
return false
|
||||
}
|
||||
|
|
@ -138,10 +160,11 @@ export function sendWin32UnicodeText(text: string): boolean {
|
|||
|
||||
/**
|
||||
* (선택적 IME 조합 확정 Space) + 커서 앞 백스페이스 N번 + UTF-16 문자열 입력을
|
||||
* 단 한 번의 Windows SendInput 호출로 원자적(atomic)으로 주입한다.
|
||||
* 단 한 번의 Windows SendInput 호출로 입력 큐에 연속해서 주입한다.
|
||||
*
|
||||
* Win32 SendInput 규약상 단일 호출 안의 INPUT 배열 사이에 사용자의 물리 키 입력이 끼어들 수 없으므로,
|
||||
* 빠른 타이핑 도중에도 지우기와 다시 쓰기가 경쟁하지 않고 < 0.5ms 안에 끝난다.
|
||||
* 배치 내부의 순서만 보장한다. 이전 스냅샷 이후 바뀐 커서/텍스트, 대상 앱의 처리 시간,
|
||||
* IME 상태까지 보장하지 않는다. 일부 입력만 성공하면 삭제/입력 배치를 재실행하지 않는다.
|
||||
*/
|
||||
export function sendWin32UnicodeReplacement(
|
||||
deleteCount: number,
|
||||
|
|
@ -177,9 +200,9 @@ export function sendWin32UnicodeReplacement(
|
|||
pairCursor += 1
|
||||
}
|
||||
|
||||
const sent = sendInput(totalEvents, buffer, inputStructSize)
|
||||
return sent === totalEvents
|
||||
return sendInputBatch(sendInput, totalEvents, buffer)
|
||||
} catch (error) {
|
||||
if (error instanceof D3ROError) throw error
|
||||
logger.warn(
|
||||
`SendInput(atomic replacement) 실행 실패: ${error instanceof Error ? error.message : String(error)}`
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue