From 8b6f7bc3ab3f39463d850fe1312681318303fc0b Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Mon, 18 Jul 2022 16:31:26 +0200 Subject: [PATCH] Make sure linebreaks are treated as ParagraphSpan.kt start/end for margin --- .../org/wordpress/aztec/spans/ParagraphSpan.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/ParagraphSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/ParagraphSpan.kt index 8f22ae74f..1860b0a77 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/ParagraphSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/ParagraphSpan.kt @@ -45,8 +45,18 @@ open class ParagraphSpan( val spanned = text as Spanned val spanStart = spanned.getSpanStart(this) val spanEnd = spanned.getSpanEnd(this) - val isFirstLine = start <= spanStart - val isLastLine = spanEnd <= end + val previousLineBreak = if (start > 1) { + text.substring(start-1, start) == "\n" + } else { + false + } + val followingLineBreak = if (end < text.length) { + text.substring(end, end + 1) == "\n" + } else { + false + } + val isFirstLine = start <= spanStart || previousLineBreak + val isLastLine = spanEnd <= end || followingLineBreak if (isFirstLine) { removeTopPadding = true fm.ascent -= paragraphStyle.verticalMargin