(hub-client) Fix remote cursor cross-line flash when typing at end of line#110
Merged
shikokuchuo merged 1 commit intomainfrom Apr 9, 2026
Merged
(hub-client) Fix remote cursor cross-line flash when typing at end of line#110shikokuchuo merged 1 commit intomainfrom
shikokuchuo merged 1 commit intomainfrom
Conversation
When a remote user types at the end of a line, their presence update (with post-edit cursor offset) can arrive before the content change. The offset maps past the newline in the pre-edit document, causing the cursor to briefly flash to the start of the next line. Render at the previous position when a small forward move would cross a line boundary.
cscheid
pushed a commit
that referenced
this pull request
Apr 21, 2026
* test: cover OT cursor tracking race cases before refactor Adds usePresence.test.ts with five regression tests covering PR #94 (cursor tracking across concurrent local edits) and PR #110 (end-of-line cross-line flash guard). Tests are written at the decoration-position level so they survive the Automerge cursor refactor tracked in #113. * refactor(presence): replace OT offset tracking with Automerge cursors (#113) Remote cursor/selection travel as Automerge cursor strings anchored to ['text'] and resolve on the receiver against its local doc. Deletes the OT machinery (transformOffset, peerStateRef, anticipatingEditRef, same-line guard) and the onDidChangeContent OT effect; modelVersion stays as a re-render trigger. `move: 'before'` for selection end is a no-op in automerge 2.2.9 — using default 'after' everywhere; deviation recorded in the plan. * test(presence): lock in sender-side cursor ordering * test: pin automerge cursor semantics as probe fixture
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.
Fixes #108. Remote cursor label flashing to the start of the next line when a collaborator types at the end of a line.
When a remote user types at the end of a line, their presence update (cursor offset in the post-edit document) can arrive before the corresponding content change. In the pre-edit document, that offset falls past the newline character, so
model.getPositionAt()maps it to line N+1 column 1 instead of line N. This causes the cursor decoration to brieflyflash to the start of the next line before snapping back when the content change arrives.
The fix saves the previous cursor position before adopting the new one. If a small forward movement (1–2 chars, the signature of a keystroke) would place the cursor on a different line, we render at the previous position instead. The content change triggers
onDidChangeContent → setModelVersion → re-render, at which point the offset maps correctly in the updated document.No changes to the OT or anticipation mechanisms — this is a pure rendering-level override.