@@ -721,7 +721,41 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
721721 return containingBoxBounds
722722 }
723723
724+ private fun getTaskListHandler (): TaskListClickHandler ? {
725+ return EnhancedMovementMethod .taskListClickHandler
726+ }
727+
724728 override fun onTouchEvent (event : MotionEvent ): Boolean {
729+ var x = event.x.toInt()
730+ var y = event.y.toInt()
731+
732+ x - = totalPaddingLeft
733+ y - = totalPaddingTop
734+
735+ x + = scrollX
736+ y + = scrollY
737+
738+ // We check whether the user tap on a checkbox of a task list. The aztec text field should be enabled and we
739+ // check whether the tap event was on the leading margin which is where the checkbox is located plus a padding
740+ // space used to increase the target size for the tap event.
741+ if (isEnabled &&
742+ x + totalPaddingStart <= (blockFormatter.listStyleLeadingMargin() + AztecTaskListSpan .PADDING_SPACE )) {
743+ val line = layout.getLineForVertical(y)
744+ val off = layout.getOffsetForHorizontal(line, x.toFloat())
745+ // If the tap event was on the leading margin, we double check whether we are tapping on a task list item.
746+ // If that is true, then we return false because we don't want to propagate the tap event to stop moving
747+ // the cursor to the item tapped.
748+ if (getTaskListHandler()?.handleTaskListClick(
749+ text,
750+ off,
751+ x,
752+ totalPaddingStart
753+ ) == true ) {
754+ refreshText(stealEditorFocus = false )
755+ return false
756+ }
757+ }
758+
725759 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P
726760 && event.action == MotionEvent .ACTION_DOWN ) {
727761 // we'll use these values in OnLongClickListener
@@ -1543,13 +1577,22 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15431577 return cursorPosition
15441578 }
15451579
1580+ open fun fromSpanned (spannedText : Spanned , isInit : Boolean = true) {
1581+ processSpannedContent(spannedText, isInit)
1582+ }
1583+
15461584 open fun fromHtml (source : String , isInit : Boolean = true) {
1547- val builder = SpannableStringBuilder ()
15481585 val parser = AztecParser (alignmentRendering, plugins)
15491586
15501587 var cleanSource = CleaningUtils .cleanNestedBoldTags(source)
15511588 cleanSource = Format .removeSourceEditorFormatting(cleanSource, isInCalypsoMode, isInGutenbergMode)
1552- builder.append(parser.fromHtml(cleanSource, context, shouldSkipTidying(), shouldIgnoreWhitespace()))
1589+ val spanned = parser.fromHtml(cleanSource, context, shouldSkipTidying(), shouldIgnoreWhitespace())
1590+
1591+ processSpannedContent(spanned)
1592+ }
1593+
1594+ private fun processSpannedContent (spannedText : Spanned , isInit : Boolean = true) {
1595+ val builder = SpannableStringBuilder (spannedText)
15531596
15541597 Format .preProcessSpannedText(builder, isInCalypsoMode)
15551598
@@ -1569,7 +1612,8 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15691612 setSelection(cursorPosition)
15701613
15711614 if (isInit) {
1572- initialEditorContentParsedSHA256 = calculateInitialHTMLSHA(toPlainHtml(false ), initialEditorContentParsedSHA256)
1615+ initialEditorContentParsedSHA256 =
1616+ calculateInitialHTMLSHA(toPlainHtml(false ), initialEditorContentParsedSHA256)
15731617 }
15741618
15751619 loadImages()
0 commit comments