Repository navigation
fix(composer): keep an empty last line's caret without adding a line - #2554
Merged
Merged
Conversation
The placeholder break that gave an empty last line a box also gave Chromium a second caret position below it, so one Shift+Enter read as one line too many and ArrowDown could leave the caret under the empty line (vastsa#2433 follow-up). The editor now marks the line with a zero-width space: Chromium resolves a caret there with a real box and offers no position of its own below the line. Chromium can merge the character into the neighbouring text node, so every read, index and caret path strips it and the draft string keeps its previous shape. Measured in Electron 43.6.0 (Chromium 150) against the production composer: the empty last line keeps its box and its caret, the editor grows by exactly one line per newline, and no caret position exists below that line. Refs vastsa#2433
This was referenced Nov 24, 2026
This was referenced Nov 25, 2026
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.
现象
#2433 的修复(#2437)后,在草稿末尾按 Shift+Enter 会出现多一条空行,而且光标还能停到那条空行下面。
根因(Electron 43.6.0 / Chromium 150 实测)
上一版给空末行加的占位是
<br data-composer-tail>。它确实给了这一行行盒,但同时给了 Chromium 一个占位之后的光标位置:<br>占位getClientRects()为空)也就是说:占位让空行可见了,但光标在这一行仍然算不出盒,而
<br>又在它下面开了第二个落点——这就是"多出一条空行、光标能停到它下面"。顺带确认:
ComposerInput的onBeforeInput在 React 19 下对beforeinput根本不触发(实测newlineCalls=0),换行一直是 Chromium 原生插入的,这条路径不受本 PR 影响。修法
把占位从 "一个换行" 换成 "一个零宽空格字符"(
U+200B):readEditorValue/editorIndexAt/editorNodeLength/editorCaretPoint全部按字符过滤,而不是按节点判断;syncTailMarker在每次提交后保证草稿以\n结尾时行尾带一个标记,行内有内容时去掉;验证
tsc -p tsconfig.json --noEmit✅node --test test/composer-*.test.mjs(tail-line / native-deletion / clipboard / agent-mention / ime)16/16 ✅docs/spec/04-ux/08-component-spec.md、docs/spec/06-delivery/e2e/conversation.mdE2E-008d。未覆盖 / 风险
sendInputEvent的 Enter 只发 keydown、CDP 的\r会重复插入),所以没有跑真实按键的端到端;上述几何结论来自 Chromium 150 上的直接 DOM 测量与组件级探针。<div>),标记会落在块末尾,行为与上一版占位一致,未额外处理。Refs #2433
Closes #2555