fix: 2 more unused-local-variable — windowMessage.ts, messages.ts
- windowMessage.ts: remove dead CLIPBOARD_THRESHOLD constant and unused pasteViaClipboard() - messages.ts: remove unused id variable and dead isToolResultMessage()
This commit is contained in:
parent
76c47956dd
commit
d20b58fc05
|
|
@ -12,9 +12,6 @@
|
||||||
|
|
||||||
import { validateHwnd, runPs, VK_MAP, MODIFIER_KEYS } from './shared.js'
|
import { validateHwnd, runPs, VK_MAP, MODIFIER_KEYS } from './shared.js'
|
||||||
|
|
||||||
/** Character count above which we switch to clipboard paste */
|
|
||||||
const CLIPBOARD_THRESHOLD = 32
|
|
||||||
|
|
||||||
/** Cache findEditChild results — window structure doesn't change while bound */
|
/** Cache findEditChild results — window structure doesn't change while bound */
|
||||||
const editChildCache = new Map<string, string | null>()
|
const editChildCache = new Map<string, string | null>()
|
||||||
|
|
||||||
|
|
@ -276,47 +273,7 @@ function buildWmCharLines(hwnd: string, text: string): string[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Paste text via clipboard into the target window.
|
* Send text to a window
|
||||||
* Uses Clipboard.SetText() + SendMessageW(Ctrl+V).
|
|
||||||
* NO global APIs (SendInput/keybd_event/SendKeys) — only window-targeted messages.
|
|
||||||
*/
|
|
||||||
function pasteViaClipboard(hwnd: string, text: string): boolean {
|
|
||||||
// Escape single quotes for PowerShell string literal
|
|
||||||
const escaped = text.replace(/'/g, "''")
|
|
||||||
const hwndExpr = `[IntPtr]::new([long]${hwnd})`
|
|
||||||
const script = `${WINMSG_TYPE}
|
|
||||||
Add-Type -AssemblyName System.Windows.Forms
|
|
||||||
|
|
||||||
# Save current clipboard
|
|
||||||
$saved = $null
|
|
||||||
try { $saved = [System.Windows.Forms.Clipboard]::GetText() } catch {}
|
|
||||||
|
|
||||||
# Set our text
|
|
||||||
[System.Windows.Forms.Clipboard]::SetText('${escaped}')
|
|
||||||
|
|
||||||
# Ctrl+V via PostMessage to the target window (NOT global keybd_event)
|
|
||||||
# Must use PostMessage + correct lParam (scan code) for Windows Terminal / ConPTY
|
|
||||||
[WinMsg]::PostMessage(${hwndExpr}, [WinMsg]::WM_KEYDOWN, [IntPtr]0x11, [WinMsg]::KeyDownLParam(0x11)) # Ctrl down
|
|
||||||
[WinMsg]::PostMessage(${hwndExpr}, [WinMsg]::WM_KEYDOWN, [IntPtr]0x56, [WinMsg]::KeyDownLParam(0x56)) # V down
|
|
||||||
[WinMsg]::PostMessage(${hwndExpr}, [WinMsg]::WM_KEYUP, [IntPtr]0x56, [WinMsg]::KeyUpLParam(0x56)) # V up
|
|
||||||
[WinMsg]::PostMessage(${hwndExpr}, [WinMsg]::WM_KEYUP, [IntPtr]0x11, [WinMsg]::KeyUpLParam(0x11)) # Ctrl up
|
|
||||||
|
|
||||||
# Brief wait for paste to complete
|
|
||||||
Start-Sleep -Milliseconds 50
|
|
||||||
|
|
||||||
# Restore clipboard
|
|
||||||
if ($saved -ne $null -and $saved -ne '') {
|
|
||||||
try { [System.Windows.Forms.Clipboard]::SetText($saved) } catch {}
|
|
||||||
} else {
|
|
||||||
try { [System.Windows.Forms.Clipboard]::Clear() } catch {}
|
|
||||||
}
|
|
||||||
Write-Output 'OK'
|
|
||||||
`
|
|
||||||
return runPs(script) === 'OK'
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send text to a window via WM_CHAR per Unicode codepoint.
|
|
||||||
* Always uses the WM_CHAR path — reliable across all window types including
|
* Always uses the WM_CHAR path — reliable across all window types including
|
||||||
* Windows Terminal / ConPTY where clipboard-based Ctrl+V doesn't work.
|
* Windows Terminal / ConPTY where clipboard-based Ctrl+V doesn't work.
|
||||||
* Window-targeted, no global input APIs.
|
* Window-targeted, no global input APIs.
|
||||||
|
|
|
||||||
|
|
@ -1431,7 +1431,6 @@ export function updateMessageLookupsIncremental(
|
||||||
const msg = messages[i]!
|
const msg = messages[i]!
|
||||||
if (msg.type === 'assistant') {
|
if (msg.type === 'assistant') {
|
||||||
const aMsg = msg as AssistantMessage
|
const aMsg = msg as AssistantMessage
|
||||||
const id = aMsg.message.id!
|
|
||||||
if (Array.isArray(aMsg.message.content)) {
|
if (Array.isArray(aMsg.message.content)) {
|
||||||
const newToolUseIDs: string[] = []
|
const newToolUseIDs: string[] = []
|
||||||
for (const content of aMsg.message.content) {
|
for (const content of aMsg.message.content) {
|
||||||
|
|
@ -2707,17 +2706,6 @@ export function mergeAssistantMessages(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isToolResultMessage(msg: Message): boolean {
|
|
||||||
if (msg.type !== 'user') {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const content = msg.message?.content
|
|
||||||
if (!content || typeof content === 'string') return false
|
|
||||||
return (content as Array<{ type: string }>).some(
|
|
||||||
block => block.type === 'tool_result',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function mergeUserMessages(a: UserMessage, b: UserMessage): UserMessage {
|
export function mergeUserMessages(a: UserMessage, b: UserMessage): UserMessage {
|
||||||
const lastContent = normalizeUserTextContent(
|
const lastContent = normalizeUserTextContent(
|
||||||
a.message.content as string | ContentBlockParam[],
|
a.message.content as string | ContentBlockParam[],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user