Conversation
CodeMirrorEditor.dispatchChange replaces the whole document without passing a selection, so CodeMirror maps the old one through the change. SelectionRange.map maps a non-empty range's from with assoc 1 and its to with assoc -1, which for a range strictly inside the replaced text gives from = new length and to = 0. The next edit at that selection throws "RangeError: Invalid change range". The dispatch now places the cursor at the old head, clamped to the new length. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0155VQF6bMAnbEaGnc1haWMp
bmesuere
commented
Sep 25, 2026
bmesuere
left a comment
Member
Author
There was a problem hiding this comment.
🤖 Reviewed. This fixes the same concrete CodeMirror selection corruption seen in Dodona, at the shared Papyros editor layer. Preserving the old head, clamped to the new document, is a sensible host-update behavior and prevents the next edit from using an inverted range. Focused tests, lint, and typecheck pass locally. No blocking findings.
This branch has not been 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.
TODO (author) — drafted by Claude: proofread, verify and remove this line.
This pull request passes an explicit cursor when
CodeMirrorEditorreplaces its whole document, so an edit made after an external value update no longer throwsRangeError: Invalid change range 482 to 0 (in doc of length 482).Sentry: DODONA-FRONTEND-2CM, thrown from
@codemirror/stateafter clicks inp-code-runner.Cause.
dispatchChangedispatches{from: 0, to: doc.length, insert}without aselection, so CodeMirror maps the current selection through the change.SelectionRange.mapmaps a non-empty range'sfromwith assoc 1 and itstowith assoc -1; for a range strictly inside the replaced text that givesfrom= new length andto= 0. The next paste, delete or typed character at that selection builds a change from the inverted range and throws. An empty cursor is not affected, which is why this only shows up with text selected.@codemirror/state6.7.6 (latest) maps ranges the same way.dispatchChangeruns for everyvaluethat does not come from the editor itself: code set by the host page, andeffectiveCodechanging when test code is added or removed. Typing does not reach it, since the setter returns early when the value equals the document.CodeMirrorEditor, so the code editor, the batch input editor and the file editor (CodeEditor,BatchInputEditor,FileEditor) all get it.Manual testing instructions
papyros.runner.codefrom the console). Type or paste: the text is inserted at the cursor and nothing is logged to the console.Checklist
CodeEditor.test.tsthat selects text inside the document, replaces the value and inserts at the selection. It throws the Sentry error before this change.Reaches production once Dodona bumps
@dodona/papyros.