github / github/copilot-cli

Mouse text selection broken in Windows Terminal after exiting Copilot session

Abierto
#2,332 0 comentarios 0 reacciones 0 asignados Ver en GitHub
area:platform-windows area:sessions
Lenguaje dominante
Shell
Estrellas
11.2k
Forks
1.9k
Merge medio
14 h 16 min
PR fusionados (30 d)
6

Descripción

### 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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.