Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-list-item-stale-positions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@milkdown/components': patch
---

Resolve deferred list item block selections against the current document.
10 changes: 6 additions & 4 deletions packages/components/src/list-item-block/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ export const listItemBlockView = $view(
const { anchor, head } = view.state.selection
div.appendChild(contentDOM)
// put the cursor to the new created list item
const anchorPos = view.state.doc.resolve(anchor)
const headPos = view.state.doc.resolve(head)
raf = requestAnimationFrame(() => {
raf = 0
if (view.isDestroyed) return
if (!anchorPos.doc.eq(view.state.doc)) return
const { state } = view
const docSize = state.doc.content.size
if (anchor > docSize || head > docSize) return
const anchorPos = state.doc.resolve(anchor)
const headPos = state.doc.resolve(head)
const selection = new TextSelection(anchorPos, headPos)
view.dispatch(view.state.tr.setSelection(selection))
view.dispatch(state.tr.setSelection(selection))
})
}

Expand Down
Loading