File tree Expand file tree Collapse file tree
ComposeTextEditor/src/commonMain/kotlin/com/darkrockstudios/texteditor/cursor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,7 +14,11 @@ fun TextEditorState.calculateCursorPosition(): CursorMetrics {
1414 val layout = currentWrappedLine.textLayoutResult
1515 val virtualLineIndex = currentWrappedLine.virtualLineIndex
1616
17- val cursorX = layout.getHorizontalPosition(charIndex, usePrimaryDirection = true )
17+ // Clamp charIndex to valid range to handle race conditions when text changes asynchronously
18+ val textLength = layout.layoutInput.text.length
19+ val safeCharIndex = charIndex.coerceIn(0 , textLength)
20+
21+ val cursorX = layout.getHorizontalPosition(safeCharIndex, usePrimaryDirection = true )
1822 val cursorY = currentWrappedLine.offset.y - scrollState.value
1923 val lineHeight = layout.multiParagraph.getLineHeight(virtualLineIndex)
2024
You can’t perform that action at this time.
0 commit comments