fix: Windows Terminal Shift+Enter 无法换行 — 改用动态 modifier 位解析#70
Merged
Conversation
…rminal compatibility SHIFT_RETURN_SEQUENCES now covers both xterm modifyOtherKeys (Shift=2) and Kitty keyboard protocol (Shift=1) encodings. Also clear input when key.return is true to prevent escape sequence artifacts from leaking into the text buffer.
Replace exact string matching in SHIFT_RETURN_SEQUENCES with CSI parameter parsing that checks modifier bits. Windows Terminal sends ESC[13;130u (modifier=128+2) where 128 is a terminal-specific flag — the old code only matched modifier=2 exactly. Also enable Kitty progressive enhancement (ESC[>1u) alongside xterm modifyOtherKeys, since Windows Terminal requires the Kitty protocol to report modified keys.
Collaborator
|
@dengmik-commits 这个PR在main分支已被revert。原因是发现几个问题:
后两个问题属于P0问题,只能以回滚处理。 |
dengmik-commits
added a commit
to dengmik-commits/deepcode-cli
that referenced
this pull request
May 18, 2026
… sync Upstream v0.1.21 reverted PR lessweb#70. Re-apply: - isShiftReturn() / isReturn() dynamic CSI modifier bit parsing - Kitty progressive enhancement (ESC[>1u) alongside xterm modifyOtherKeys - Clear input when key.return is true (safety net)
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Windows Terminal 下 Shift+Enter 无法换行,行为等同于普通回车,直接提交输入。
此问题在 #52 (e56a112) 中曾尝试修复,当时添加了
enableTerminalExtendedKeys(xterm modifyOtherKeys level 1)和两个额外序列(�[13;2~、�[27;2;13~)。#52 为什么没修好
根本原因是
SHIFT_RETURN_SEQUENCES使用精确字符串匹配(Set.has())来比对 modifier 值。xterm 标准中 Shift 修饰键 = 2,序列为�[13;2u。但 Windows Terminal 会在 modifier 上附加额外的标志位,实际发送的序列是:其中
128是终端特有的标志位。130 & 2 === 2,Shift 确实被按下了——但精确字符串�[13;130u不在 Set 中,被视为未知转义序列,key.meta被设为true,按键被静默丢弃。此外,仅靠 xterm
modifyOtherKeys(�[>4;1m)不够——Windows Terminal 需要 Kitty 渐进增强协议(�[>1u)才会以 CSI 格式上报修饰键。修复内容
改动两个文件:
src/ui/prompt/useTerminalInput.tsisShiftReturn(raw)— 动态解析 CSI 序列,提取 modifier 参数,用(mod & 2) !== 0按位检测 Shift。不关心 terminal 附加的其他标志位,能匹配 2、6、130 等任意包含 Shift 位的 modifier 值。isReturn(raw)— 识别任意 CSI 格式的 Enter(�[13u、�[13;\d+u等),兜底处理终端将 Enter 转义为 CSI 格式的情况。两个函数都优先回退到已有的
SHIFT_RETURN_SEQUENCES和META_RETURN_SEQUENCESSet,保证向后兼容。key.return检测简化为isReturn(raw),key.shift检测使用isShiftReturn(raw)。src/ui/prompt/cursor.tsenableTerminalExtendedKeys()同时发送 xtermmodifyOtherKeys(�[>4;1m)和 Kitty 渐进增强(�[>1u)。终端会忽略不认识的序列,同时发送两者安全无副作用。disableTerminalExtendedKeys()发送对应的关闭序列(�[>4;0m+�[<u)。验证
诊断脚本确认 Windows Terminal 对 Shift+Enter 发送
�[13;130u。已在 Windows Terminal 的 PowerShell 和 CMD 标签页中实测通过。