External editor (Ctrl+G): TUI is not hidden before launching editor, causing screen corruption and lost keystrokes

未關閉
#1,092 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
66/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
javascript, neovim
領域
cli

研究方向

Start by locating openInEditor and openMemoryFileInEditor, then trace how withLegacyKeyboard wraps the editor spawn without stopping the TUI. Compare that path with the referenced pi pattern: this.tui.stop() before spawning, and this.tui.start() plus this.tui.requestRender(true) in a finally block. Reproduce with cmd, Ctrl+G, and nvim; done means the editor owns the terminal cleanly, keystrokes are not lost, the prompt is captured on return, and the TUI redraws fully.

由索引模型根據 Issue 內容生成。

描述

Summary

When Command Code launches an external editor via Ctrl+G, it does not stop/hide its TUI first. The TUI's render loop (git-polling statusline, autocomplete/snippet UI) keeps writing to the terminal and reading stdin while the editor (e.g. nvim) is running. This causes screen corruption and intermittent keystroke loss (Escape, ZZ), so the prompt is sometimes not captured on return.

This is not specific to the kitty keyboard protocol — it reproduces in wezterm, ghostty, alacritty, and kitty.

Reproduction

  1. Run cmd in any of the terminals above.
  2. Type a prompt, press Ctrl+G to open the external editor (nvim).
  3. Type text, idle ~5s, type more, idle ~5s, then ZZ.
  4. Observe: typed text often does not appear in nvim; ZZ may not register; nvim can hang ("Save and close the editor to continue...").

Evidence (cmd vs pi, side-by-side)

Captured in tmux (same terminal, same nvim config). pi calls tui.stop() before spawning the editor and tui.start() after; cmd does not.

Tool nvim opened typing registered survived idle ZZ exited text captured
pi (reference) YES YES YES YES YES
cmd YES NO (buffer stayed empty) n/a NO (stuck) NO

Root cause

In openInEditor (and openMemoryFileInEditor), cmd wraps the spawn in withLegacyKeyboard, which only pops/pushes the kitty keyboard protocol. It never stops the TUI render loop or stdin handling. Contrast pi:

this.tui.stop();
try {
  let result = await editInExternalEditor({ command, content });
  ...
} finally {
  this.tui.start();
  this.tui.requestRender(true);
}

Because cmd's TUI keeps rendering and reading stdin, keystrokes are consumed and the screen is corrupted while nvim is active.

Suggested fix

Mirror pi: before spawning the external editor, stop the TUI (stop rendering + release stdin); after the editor exits, restart the TUI and request a full render. This is the same pattern opencode uses.

nvim-side mitigations already applied (insufficient)

  • Disabled folke/noice.nvim (fixed nvim freeze on exit after idle).
  • ttimeout = true, ttimeoutlen = 0 (helps Escape registration).

These address nvim-specific issues but cannot fix a parent TUI that keeps writing to the terminal / reading stdin. Screen corruption and text-capture loss remain until cmd hides its TUI.

Environment

  • Command Code v1.88.2
  • nvim 0.12.6
  • Reproduced in wezterm, ghostty, alacritty, kitty
主要語言
沒有語言資料
星號
4.2k
分支
377
平均合併
1 天 3 小時
30 天內合併 PR
6

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

CommandCodeAI/command-code 的其他 Issue

查看 CommandCodeAI/command-code 的全部 Issue

相似的 Issue

更多 CLI Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。