Repository navigation
fix(composer): keep an empty last line's caret on that line - #2437
Merged
Merged
Conversation
Chromium has no layout box for a line that holds nothing, so a caret left after the final line break resolves to the line above: the next keystroke, and an IME composition, land on the previous line while the draft string stays correct. The composer's own DOM evidence in vastsa#2433 ("1test\n2test\n" with the caret in the trailing "\n" node) reproduces it on Electron 43.6.0. Paint a placeholder break on an empty last line and skip it from every read, index and caret path, so the draft string and its indices do not change. Re-sync it after each commit instead of inside the input event, where mutating the editor makes Chromium insert the line break twice. Place a new Shift+Enter line's caret by draft index rather than a DOM offset. fixes vastsa#2433
This was referenced Nov 19, 2026
Collaborator
This was referenced Nov 24, 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.

Summary / 概要
#2433:草稿最后一行为空时,这一行在 DOM 里没有任何布局盒,Chromium 会把「末尾换行之后」的光标归属到上一行,导致后续按键与 IME 组合落到上一行(草稿字符串本身仍正确)。在真实 Electron 43.6.0(Chromium 150)上用生产 composer 组件复现:1test2test\nx1testy\nni提交你1testni\n→1testn你\n在
editor.ts里为空末行补一个占位换行(<br data-composer-tail aria-hidden="true">)提供布局盒,所有读取 / 索引 / 光标路径跳过它,草稿字符串与索引不变;在每次草稿提交后的 layout effect 里同步(不在input事件内改 DOM——实测那样会让 Chromium 把换行插两次);Shift+Enter新行改为按草稿索引放光标。修复后同一套探针:
1test\n2test\nx、1test\ny、IME1test\nni→1test\n你;Backspace 合并空末行后1test\n2test且无残留占位;中间行删空行为不变(1test\nz\n3test,Chromium 150 本来就正常,规格已注明)。Requirement link / 需求关联
1test\n2test\n、光标位于末尾"\n"节点offset=1)Verification / 验证
main0699f6aca(已 rebase,git diff --check✔)tsc -p apps/desktop --noEmit✔;biome lint✔node --test apps/desktop/test/composer-*.test.mjs:268/270 通过,其中包含真实 Electron 的 user-path 用例(composer-agent-mention-user-path、composer-deep-file-search-user-path)composer-file-references为 WindowssymlinkEPERM,改动前同样失败,属环境限制而非本次改动docs/spec/04-ux/08-component-spec.md(Native deletion 段)、docs/spec/06-delivery/e2e/conversation.md(E2E-008d)apps/desktop/test/composer-tail-line.test.mjs(占位判定 + 读取 / 索引 / 绘制契约)pnpm test:e2e:*(live-model 车道,需要测试用 API Key)与verify:ui:*(未获授权);替代验证为 Electron 真机探针(真实键盘与 IME 事件)Closes #2433