Skip to content

Commit

Permalink
Merge pull request #241 from MohamedRejeb/1.x
Browse files Browse the repository at this point in the history
Fix bug with undo
  • Loading branch information
MohamedRejeb authored Apr 7, 2024
2 parents 87178d4 + 8751766 commit 00e129c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ class RichTextState internal constructor(
*/
private fun handleAddingCharacters() {
val typedCharsCount = tempTextFieldValue.text.length - textFieldValue.text.length
var startTypeIndex = tempTextFieldValue.selection.min - typedCharsCount
var startTypeIndex = tempTextFieldValue.selection.max - typedCharsCount
val typedText = tempTextFieldValue.text.substring(
startIndex = startTypeIndex,
endIndex = startTypeIndex + typedCharsCount,
Expand All @@ -817,7 +817,10 @@ class RichTextState internal constructor(
val newTypedText = beforeTypedText + paragraphStartText + typedText + afterTypedText
tempTextFieldValue = tempTextFieldValue.copy(
text = newTypedText,
selection = TextRange(tempTextFieldValue.selection.min + indexDiff),
selection = TextRange(
(tempTextFieldValue.selection.min + indexDiff).coerceAtLeast(0),
(tempTextFieldValue.selection.max + indexDiff).coerceAtMost(newTypedText.length),
),
)
}

Expand Down

0 comments on commit 00e129c

Please sign in to comment.