@@ -142,6 +142,49 @@ export function openExternalText(platform: Platform, paths: RunPaths, candidateP
142142 return filePath
143143}
144144
145+ export function selectExternalText ( platform : Platform ) : void {
146+ if ( platform === 'macos' ) {
147+ runMacHotkey ( [ 'Meta' , 'a' ] )
148+ return
149+ }
150+ if ( ! activeWindowsExternalTextPid ) throw new Error ( 'No external text window is active' )
151+
152+ const script = [
153+ 'Add-Type -AssemblyName UIAutomationClient' ,
154+ 'Add-Type -AssemblyName UIAutomationTypes' ,
155+ `Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public static class NativeMouse { [DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y); [DllImport("user32.dll")] public static extern void mouse_event(uint flags, uint x, uint y, uint data, UIntPtr extra); }'` ,
156+ `$notepad = Get-Process -Id ${ activeWindowsExternalTextPid } -ErrorAction Stop` ,
157+ '$shell = New-Object -ComObject WScript.Shell' ,
158+ 'if (-not $shell.AppActivate($notepad.Id)) { throw "Notepad window could not be activated" }' ,
159+ 'Start-Sleep -Milliseconds 200' ,
160+ '$root = [System.Windows.Automation.AutomationElement]::RootElement' ,
161+ `$process = [System.Windows.Automation.PropertyCondition]::new([System.Windows.Automation.AutomationElement]::ProcessIdProperty, ${ activeWindowsExternalTextPid } )` ,
162+ '$window = $root.FindFirst([System.Windows.Automation.TreeScope]::Children, $process)' ,
163+ 'if (-not $window) { throw "Notepad automation window was not found" }' ,
164+ '$documentType = [System.Windows.Automation.PropertyCondition]::new([System.Windows.Automation.AutomationElement]::ControlTypeProperty, [System.Windows.Automation.ControlType]::Document)' ,
165+ '$editType = [System.Windows.Automation.PropertyCondition]::new([System.Windows.Automation.AutomationElement]::ControlTypeProperty, [System.Windows.Automation.ControlType]::Edit)' ,
166+ '$textArea = $window.FindFirst([System.Windows.Automation.TreeScope]::Descendants, [System.Windows.Automation.OrCondition]::new($documentType, $editType))' ,
167+ 'if (-not $textArea) { throw "Notepad text area was not found" }' ,
168+ '$rect = $textArea.Current.BoundingRectangle' ,
169+ '$startX = [int]($rect.Left + 8)' ,
170+ '$endX = [int]($rect.Right - 8)' ,
171+ '$y = [int]($rect.Top + 18)' ,
172+ '$null = [NativeMouse]::SetCursorPos($startX, $y)' ,
173+ '[NativeMouse]::mouse_event(0x0002, 0, 0, 0, [UIntPtr]::Zero)' ,
174+ 'for ($step = 1; $step -le 12; $step += 1) {' ,
175+ ' $x = [int]($startX + (($endX - $startX) * $step / 12))' ,
176+ ' $null = [NativeMouse]::SetCursorPos($x, $y)' ,
177+ ' Start-Sleep -Milliseconds 25' ,
178+ '}' ,
179+ '[NativeMouse]::mouse_event(0x0004, 0, 0, 0, [UIntPtr]::Zero)' ,
180+ 'Start-Sleep -Milliseconds 500'
181+ ] . join ( '; ' )
182+ execFileSync ( 'powershell.exe' , [ '-NoProfile' , '-NonInteractive' , '-Command' , script ] , {
183+ stdio : 'ignore' ,
184+ timeout : 10_000
185+ } )
186+ }
187+
145188export function chooseNativeFile ( platform : Platform , paths : RunPaths , candidatePath : string ) : string {
146189 const filePath = resolveAllowedPath ( candidatePath , [ paths . fixtures , paths . workspace , paths . evidence ] )
147190 if ( ! existsSync ( filePath ) ) throw new Error ( `Selected file does not exist: ${ filePath } ` )
0 commit comments