diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/utils/TextLayoutResultExt.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/utils/TextLayoutResultExt.kt index 118f19c5..ea06de87 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/utils/TextLayoutResultExt.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/utils/TextLayoutResultExt.kt @@ -31,13 +31,19 @@ fun TextLayoutResult.getBoundingBoxes( if (multiParagraph.lineCount == 0) return emptyList() - val lastLinePosition = - Offset( - x = multiParagraph.getLineRight(multiParagraph.lineCount - 1), - y = multiParagraph.getLineTop(multiParagraph.lineCount - 1) - ) + var lastOffset = 0 + var lastNonEmptyLineIndex = multiParagraph.lineCount - 1 + + while (lastOffset == 0 && lastNonEmptyLineIndex >= 0) { + val lastLinePosition = + Offset( + x = multiParagraph.getLineRight(lastNonEmptyLineIndex), + y = multiParagraph.getLineTop(lastNonEmptyLineIndex) + ) - val lastOffset = multiParagraph.getOffsetForPosition(lastLinePosition) + lastOffset = multiParagraph.getOffsetForPosition(lastLinePosition) + lastNonEmptyLineIndex-- + } if (startOffset >= lastOffset) return emptyList()