Skip to content

Commit d269bff

Browse files
committed
Log the content of the editor in case HeadingHandler.handleNewlineInBody has start > end
1 parent 272f421 commit d269bff

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecExceptionHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AztecExceptionHandler(private val logHelper: ExceptionHandlerHelper?, priv
3333
AppLog.e(AppLog.T.EDITOR, "HTML Content of Aztec Editor before the crash " + visualEditor.toPlainHtml(false))
3434
} catch (e: Throwable) {
3535
AppLog.e(AppLog.T.EDITOR, "HTML Content of Aztec Editor before the crash is unavailable, log the details instead")
36-
AztecLog.logEditorContentDetails(visualEditor)
36+
AztecLog.logContentDetails(visualEditor)
3737
}
3838
}
3939

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package org.wordpress.aztec.handlers
22

33
import android.text.Spannable
44
import android.text.Spanned
5+
import org.wordpress.android.util.AppLog
56
import org.wordpress.aztec.Constants
67
import org.wordpress.aztec.spans.IAztecBlockSpan
78
import org.wordpress.aztec.spans.IAztecNestable
9+
import org.wordpress.aztec.util.AztecLog
810
import org.wordpress.aztec.util.SpanWrapper
911
import org.wordpress.aztec.watchers.BlockElementWatcher.TextChangeHandler
1012

@@ -115,6 +117,13 @@ abstract class BlockHandler<SpanType : IAztecBlockSpan>(val clazz: Class<SpanTyp
115117

116118
companion object {
117119
fun set(text: Spannable, block: IAztecBlockSpan, start: Int, end: Int) {
120+
if (start > end) {
121+
AppLog.w(AppLog.T.EDITOR, "BlockHandler.set static method called with start > end. Start: " + start + " End: " + end)
122+
AppLog.w(AppLog.T.EDITOR, "Invoked with block type of " + block.javaClass.canonicalName)
123+
AztecLog.logContentDetails(text)
124+
return
125+
}
126+
118127
val flags = Spanned.SPAN_PARAGRAPH
119128
if (SpanWrapper.isInvalidParagraph(text, start, end, flags)) return
120129

aztec/src/main/kotlin/org/wordpress/aztec/util/Azteclog.kt

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

3+
import android.text.Spannable
34
import org.json.JSONArray
45
import org.json.JSONException
56
import org.json.JSONObject
@@ -14,23 +15,27 @@ class AztecLog {
1415
}
1516

1617
companion object {
17-
fun logEditorContentDetails(aztecText: AztecText) {
18+
fun logContentDetails(aztecText: AztecText) {
19+
AppLog.d(AppLog.T.EDITOR, "Below are the details of the content in the editor:")
20+
logContentDetails(aztecText.text)
21+
}
22+
23+
fun logContentDetails(text: Spannable) {
1824
try {
1925
val logContentJSON = JSONObject()
20-
logContentJSON.put("content", aztecText.text.toString())
21-
logContentJSON.put("length", aztecText.text.length)
26+
logContentJSON.put("content", text.toString())
27+
logContentJSON.put("length", text.length)
2228
val spansJSON = JSONArray()
23-
val spans = aztecText.text.getSpans(0, aztecText.text.length, Any::class.java)
29+
val spans = text.getSpans(0, text.length, Any::class.java)
2430
spans.forEach {
2531
val currenSpanJSON = JSONObject()
26-
currenSpanJSON.put("clasz", it.javaClass.name)
27-
currenSpanJSON.put("start", aztecText.text.getSpanStart(it))
28-
currenSpanJSON.put("end", aztecText.text.getSpanEnd(it))
29-
currenSpanJSON.put("flags", aztecText.text.getSpanFlags(it))
32+
currenSpanJSON.put("clazz", it.javaClass.name)
33+
currenSpanJSON.put("start", text.getSpanStart(it))
34+
currenSpanJSON.put("end", text.getSpanEnd(it))
35+
currenSpanJSON.put("flags", text.getSpanFlags(it))
3036
spansJSON.put(currenSpanJSON)
3137
}
3238
logContentJSON.put("spans", spansJSON)
33-
AppLog.d(AppLog.T.EDITOR, "Below are the details of the content in the editor:")
3439
AppLog.d(AppLog.T.EDITOR, logContentJSON.toString())
3540
} catch (e: JSONException) {
3641
AppLog.e(AppLog.T.EDITOR, "Uhh ohh! There was an error logging the content of the Editor. This should" +

0 commit comments

Comments
 (0)