Skip to content

Commit a17600c

Browse files
committed
Move specific condition that checks if "new line" is at the end of the block in BlockHandler.getNewlinePositionType()
1 parent 732ce40 commit a17600c

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/handlers/BlockHandler.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ abstract class BlockHandler<SpanType : IAztecBlockSpan>(val clazz: Class<SpanTyp
103103
return PositionType.BUFFER_END
104104
}
105105

106+
if (atEndOfBlock) {
107+
return PositionType.BUFFER_END
108+
}
109+
106110
// no special case applied so, newline is in the "body" of the block
107111
return PositionType.BODY
108112
}

aztec/src/main/kotlin/org/wordpress/aztec/handlers/HeadingHandler.kt

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.wordpress.aztec.handlers
22

33
import android.text.Spannable
4-
import org.wordpress.aztec.Constants
54
import org.wordpress.aztec.spans.AztecHeadingSpan
65
import org.wordpress.aztec.watchers.TextDeleter
76

@@ -27,26 +26,13 @@ class HeadingHandler : BlockHandler<AztecHeadingSpan>(AztecHeadingSpan::class.ja
2726
TextDeleter.mark(text, newlineIndex, newlineIndex + 1)
2827
}
2928

30-
// fun handleNewlineAtTextEnd()
31-
// got a newline while being at the end-of-text. We'll let the current list item engulf it and will wait
32-
// for the end-of-text marker event in order to attach the new list item to it when that happens.
29+
override fun handleNewlineAtTextEnd() {
30+
block.end = newlineIndex + 1
31+
}
3332

3433
override fun handleNewlineInBody() {
35-
36-
// if the new newline is the second-last character of the block and the last one is a newline (which
37-
// is a visual newline) or the end-of-buffer marker, or it's the last character of the text then it's the last
38-
// actual character of the block
39-
val atEndOfBlock = (newlineIndex == block.end - 2 &&
40-
(text[block.end - 1] == Constants.NEWLINE || text[block.end - 1] == Constants.END_OF_BUFFER_MARKER)) ||
41-
newlineIndex == text.length - 1
42-
43-
if (atEndOfBlock) {
44-
// newline added at the end of the block (right before its visual newline) so, just end the block and
45-
// not add a new block after it
46-
} else {
47-
// newline added at some position inside the block. Let's split the block into two
48-
cloneHeading(text, block.span, newlineIndex + 1, block.end)
49-
}
34+
// newline added at some position inside the block. Let's split the block into two
35+
cloneHeading(text, block.span, newlineIndex + 1, block.end)
5036

5137
block.end = newlineIndex + 1
5238
}

0 commit comments

Comments
 (0)