Skip to content

Commit 105202d

Browse files
committed
Bring back the check if "atTextEnd" in HeadingHandler since moving it to the BlockHandler introduces many issues with lists.
1 parent 0d89c78 commit 105202d

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ 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-
110106
// no special case applied so, newline is in the "body" of the block
111107
return PositionType.BODY
112108
}

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

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

33
import android.text.Spannable
4+
import org.wordpress.aztec.Constants
45
import org.wordpress.aztec.spans.AztecHeadingSpan
56
import org.wordpress.aztec.watchers.TextDeleter
67

@@ -26,13 +27,25 @@ class HeadingHandler : BlockHandler<AztecHeadingSpan>(AztecHeadingSpan::class.ja
2627
TextDeleter.mark(text, newlineIndex, newlineIndex + 1)
2728
}
2829

29-
override fun handleNewlineAtTextEnd() {
30-
block.end = newlineIndex + 1
31-
}
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.
3233

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

3750
block.end = newlineIndex + 1
3851
}

0 commit comments

Comments
 (0)