Mouse text selection broken in Windows Terminal after exiting Copilot session
- 主要語言
- Shell
- 星號
- 11.2k
- 分支
- 1.9k
- 平均合併
- 14 小時 16 分鐘
- 30 天內合併 PR
- 6
描述
### Describe the bug
After starting and exiting a Copilot CLI session in Windows Terminal, mouse text selection stops working in the PowerShell tab. Before launching Copilot, left-click drag to select/copy text works normally. After the session ends, selection no longer responds to mouse input.
### Root cause analysis
Copilot enables terminal mouse tracking during the session but does not fully restore terminal state on exit. Investigation found:
- Win32 console mode flags (`ENABLE_QUICK_EDIT_MODE`, `ENABLE_MOUSE_INPUT`) are restored correctly — the issue is not at the console API layer.
- Sending VT mouse tracking disable sequences (`ESC[?1000l`, `ESC[?1002l`, `ESC[?1003l`, `ESC[?1006l`, etc.) after exit has no effect.
- Soft terminal reset (`ESC[!p`) has no effect.
- **Only a hard terminal reset (`ESC c` / RIS) restores selection**, suggesting the stuck state is at the Windows Terminal / ConPTY layer and not addressable through individual mode disable sequences.
This appears related to #1823 (mouse click regression) and #1424 (console left in raw/VT mode), but is a distinct symptom: selection remains broken *after* the Copilot process has exited and control has returned to the shell.
### Affected version
GitHub Copilot CLI 1.0.12.
### Steps to reproduce the behavior
1. Open a new PowerShell tab in Windows Terminal
2. Verify left-click drag selects text (it works)
3. Run `copilot`
4. Use the session normally, then exit (e.g. `/exit` or Ctrl+C)
5. Try to left-click drag to select text — it no longer works
### Expected behavior
Mouse text selection should work the same after exiting a Copilot session as it did before starting one.
### Workaround
Wrap the `copilot` command in a PowerShell function that saves the screen buffer, performs a hard terminal reset (`ESC c`), then re-displays the saved content:
```powershell
# Add to $PROFILE
function Start-CopilotWithTerminalFix {
copilot @args
# Save screen buffer before reset
$rawUI = $Host.UI.RawUI
$width = $rawUI.BufferSize.Width
$cursorY = $rawUI.CursorPosition.Y
$startY = [Math]::Max(0, $cursorY - 200)
$rect = [System.Management.Automation.Host.Rectangle]::new(0, $startY, $width - 1, $cursorY)
$saved = $rawUI.GetBufferContents($rect)
$rows = $cursorY - $startY + 1
# Hard reset to fix mouse tracking state
[Console]::Out.Write("`ec")
# Re-display saved buffer content (colors are lost)
$sb = [System.Text.StringBuilder]::new()
for ($r = 0; $r -lt $rows; $r++) {
$line = [System.Text.StringBuilder]::new($width)
for ($c = 0; $c -lt $width; $c++) {
[void]$line.Append($saved[$r, $c].Character)
}
[void]$sb.AppendLine($line.ToString().TrimEnd())
}
Write-Host $sb.ToString() -NoNewline
}
Set-Alias -Name copilot -Value Start-CopilotWithTerminalFix
```
Note: The hard reset clears terminal colors, so the re-displayed buffer content will be unformatted text. The resume session GUID and other output are preserved.
### Environment
- OS: Windows 11
- Shell: PowerShell 7.6.0
- Terminal: Windows Terminal
- Copilot CLI: 1.0.12
貢獻指南
評估
這個 Issue 還沒有評估資料。