Skip to content

fix(edit): selection changes are followed again after a re-attach - #2

Merged
pierreneter merged 1 commit into
p10node:mainfrom
abe238:fix/selection-after-reattach
Nov 14, 2026
Merged

pierreneter merged 1 commit into
p10node:mainfrom
abe238:fix/selection-after-reattach

Conversation

@abe238

@abe238 abe238 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What happens

After the editor re-attaches its input (for example when the document view is re-mounted), typing stops following the caret. If you click in a paragraph, scroll away and type, the text lands at the top of the document instead of where the caret was.

Cause

RichInput.detach cancels the pending animation frame but keeps its handle in this.raf. onSelChange returns early while this.raf is set, so after a detach and attach every later selection change is ignored. The editor no longer knows where the caret is, and the page that holds the caret is not kept mounted while scrolling.

Fix

One line: reset this.raf to 0 in detach.

Test

test/input-reattach.test.ts attaches, changes the selection, detaches, attaches again, and checks that a selection change is still followed. It fails on main without the change and passes with it.

Checked on current main (v0.13.0): bun test test/ passes (497 tests), bun run typecheck passes. I did not run the e2e suite.

Found while building on office-engine. Thank you for the project.

RichInput.detach cancelled the pending animation frame but kept its handle,
so every later selection change returned early. The editor then stopped
knowing where the caret was: the page holding the caret was no longer kept
mounted while scrolling, and text typed after scrolling away landed at the
top of the document instead of at the caret.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@pierreneter

Copy link
Copy Markdown
Member

Hi @abe238, thank you for reporting this bug so early. I did get your email and have not had the chance to reply yet, so thank you all the more for opening this PR.

This morning, right after your first email, I quickly pushed a fix in 0.13.1, but it looks like that still did not solve it. I am really glad you found the cause and fixed it.

@pierreneter
pierreneter merged commit 2333154 into p10node:main Nov 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants