Repository navigation
Conversation
…corator When the first child of the document is a non-inline decorator node (block image, horizontal rule, ...), moving the caret left/up past the boundary parks the selection at root offset 0 — a position with no text anchor. The browser then renders a floating caret across the block (the 'horizontal cursor' artifact), and the empty leading paragraph that editors like Linear insert in this case never appears. This adds a passive normalization listener to registerCursorNode: - $isCaretAtRootStartBeforeBlockDecorator detects the parked caret - $insertParagraphBeforeRootStartBlock inserts a fresh empty paragraph and anchors the selection inside it - the listener runs on every update (with a re-entrancy guard + microtask deferral to avoid update loops), so every caret path — ArrowLeft from the block below, ArrowUp, clicking the top gap, NodeSelection + ArrowLeft — lands in a real text anchor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
👍 @arvinxx |
commit: |
This branch was successfully deployed
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.
🔗 Related issue / 背景
来自 @lobehub 主仓库 dev 频道的边缘 case 反馈:
🐛 问题分析
当文档第一个子节点是 非 inline 的 DecoratorNode(BlockImageNode、HorizontalRuleNode 等)时:
现有的
CursorNode机制只覆盖了 inline 装饰节点(行内图片)的光标锚点,块级装饰节点前没有对应处理。✨ 修复方案
在
registerCursorNode中新增一个被动规范化 listener(Linear 同款行为):()— 检测「collapsed selection 停在 root offset 0 且第一个子节点是非 inline 装饰节点」()— 在块前插入空段落并把 selection 锚定进去queueMicrotask延迟避免 update 循环),因此所有光标落点路径都会被规范化:关键细节:caret 停在 root offset 0 的 selection 在 DOM reconcile 时本身无法保留,所以 update 事务内只做结构校验、不重新检查 selection,插入的段落自带全新合法 selection。
✅ 验证
cursor-root-start.test.ts):detector 正/反例、插入后结构与 caret 落点、ArrowLeft 跨块边界vitest run src/plugins/common:8 个文件 50 个测试全部通过,无回归tsc --noEmit通过;循环依赖检查通过📌 备注
粘贴图片时「先横向光标再转纵向」是同一根因的另一种表现:块级图片插入后 selection 短暂落在不可表达的 DOM 位置。本次的被动规范化会在下一次 update 时把这种情况收敛掉。