github / github/copilot-cli

Mouse text selection broken in Windows Terminal after exiting Copilot session

未关闭
#2,332 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area:platform-windows area:sessions
主要语言
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

贡献指南

打开贡献指南

调研方向

Reproduce the issue in Windows Terminal with a PowerShell tab using the listed steps, then trace the Copilot session exit and terminal cleanup path. Compare terminal state before launch and after exit, and verify that mouse text selection works normally afterward without requiring the hard-reset workaround.

由索引模型根据 Issue 内容生成。

评估

技术栈
powershell, shell
领域
cli, operating-systems
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。