From 67b1618f5ae9cf9e7cb630ae32b4851092aab818 Mon Sep 17 00:00:00 2001 From: Yann Badoual Date: Wed, 22 Mar 2023 15:15:26 +0100 Subject: [PATCH] Fix line computation --- .../storyeditor/util/TextLayoutResult.kt | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/story-editor/src/main/java/com/github/badoualy/storyeditor/util/TextLayoutResult.kt b/story-editor/src/main/java/com/github/badoualy/storyeditor/util/TextLayoutResult.kt index 7537b5e..16f6da9 100644 --- a/story-editor/src/main/java/com/github/badoualy/storyeditor/util/TextLayoutResult.kt +++ b/story-editor/src/main/java/com/github/badoualy/storyeditor/util/TextLayoutResult.kt @@ -6,14 +6,11 @@ internal fun TextLayoutResult.getLines(): String { val input = layoutInput.text.toString() if (input.isEmpty()) return "" - return buildString { - var currentIndex = 0 - - repeat(lineCount) { line -> - val lineEnd = getLineEnd(line) - appendLine(input.substring(currentIndex, lineEnd)) - - currentIndex = lineEnd - } - }.trim() + return (0 until lineCount).joinToString("\n") { line -> + val lineContent = input.substring( + getLineStart(line), + getLineEnd(line, visibleEnd = true) + ) + lineContent + } }