Skip to content

Commit 5231c74

Browse files
iHiDclaude
andauthored
Clamp paste cursor position to document length (#8616)
The moveCursorByPasteLength extension could calculate a cursor position beyond the document length after a paste, causing a RangeError. This happens because the setTimeout callback reads the post-paste cursor position and adds the paste length again, overshooting the document end. Closes #8606 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0506c0d commit 5231c74

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

app/javascript/components/bootcamp/JikiscriptExercisePage/CodeMirror/extensions/move-cursor-by-paste-length.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export const moveCursorByPasteLength = EditorView.domEventHandlers({
1111
const pastedLength = pastedText.length
1212

1313
view.dispatch({
14-
selection: { anchor: from + pastedLength },
14+
selection: {
15+
anchor: Math.min(from + pastedLength, view.state.doc.length),
16+
},
1517
scrollIntoView: true,
1618
})
1719
}, 0)

0 commit comments

Comments
 (0)