Skip to content

Commit 0a4a1b2

Browse files
authored
Merge pull request #812 from wordpress-mobile/fix/list-handling-in-gutenberg-attempt1
Fix list handling in Gutenberg
2 parents 7371aec + 87e7f35 commit 0a4a1b2

File tree

3 files changed

+6
-79
lines changed

3 files changed

+6
-79
lines changed

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

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ import org.wordpress.aztec.watchers.DeleteMediaElementWatcherAPI25AndHigher
102102
import org.wordpress.aztec.watchers.DeleteMediaElementWatcherPreAPI25
103103
import org.wordpress.aztec.watchers.EndOfBufferMarkerAdder
104104
import org.wordpress.aztec.watchers.EndOfParagraphMarkerAdder
105-
import org.wordpress.aztec.watchers.EnterPressedWatcher
106105
import org.wordpress.aztec.watchers.FullWidthImageElementWatcher
107106
import org.wordpress.aztec.watchers.InlineTextWatcher
108107
import org.wordpress.aztec.watchers.ParagraphBleedAdjuster
@@ -320,7 +319,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
320319
}
321320

322321
interface OnAztecKeyListener {
323-
fun onEnterKey() : Boolean
322+
fun onEnterKey(text: Spannable, firedAfterTextChanged: Boolean, selStart: Int, selEnd: Int) : Boolean
324323
fun onBackspaceKey() : Boolean
325324
}
326325

@@ -521,7 +520,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
521520
if (event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER) {
522521
// Check if the external listener has consumed the enter pressed event
523522
// In that case stop the execution
524-
if (onAztecKeyListener?.onEnterKey() == true) {
523+
if (onAztecKeyListener?.onEnterKey(text, false, 0, 0) == true) {
525524
return true
526525
}
527526
}
@@ -557,11 +556,6 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
557556
}
558557

559558
private fun install() {
560-
// Keep the enter pressed watcher at the beginning of the watchers list.
561-
// We want to intercept Enter.key as soon as possible, and before other listeners start modifying the text.
562-
// Also note that this Watchers, when the AztecKeyListener is set, keep hold a copy of the content in the editor.
563-
EnterPressedWatcher.install(this)
564-
565559
ParagraphBleedAdjuster.install(this)
566560
ParagraphCollapseAdjuster.install(this)
567561

@@ -1239,15 +1233,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
12391233
// returns regular or "calypso" html depending on the mode
12401234
// default behavior returns HTML from this text
12411235
fun toHtml(withCursorTag: Boolean = false): String {
1242-
val html = toPlainHtml(withCursorTag)
1243-
1244-
if (isInCalypsoMode) {
1245-
// calypso format is a mix of newline characters and html
1246-
// paragraphs and line breaks are added on server, from newline characters
1247-
return Format.addSourceEditorFormatting(html, true)
1248-
} else {
1249-
return html
1250-
}
1236+
return toHtml(text, withCursorTag)
12511237
}
12521238

12531239
// general function accepts any Spannable and converts it to regular or "calypso" html
@@ -1267,15 +1253,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
12671253
// platform agnostic HTML
12681254
// default behavior returns HTML from this text
12691255
fun toPlainHtml(withCursorTag: Boolean = false): String {
1270-
return if (Looper.myLooper() != Looper.getMainLooper()) {
1271-
runBlocking {
1272-
withContext(Dispatchers.Main) {
1273-
parseHtml(text, withCursorTag)
1274-
}
1275-
}
1276-
} else {
1277-
parseHtml(text, withCursorTag)
1278-
}
1256+
return toPlainHtml(text, withCursorTag)
12791257
}
12801258

12811259
// general function accepts any Spannable and converts it to platform agnostic HTML
@@ -1295,7 +1273,6 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
12951273
val parser = AztecParser(plugins)
12961274
val output: SpannableStringBuilder
12971275
try {
1298-
//output = SpannableStringBuilder(text)
12991276
output = SpannableStringBuilder(content)
13001277
} catch (e: Exception) {
13011278
// FIXME: Remove this log once we've data to replicate the issue, and fix it in some way.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AztecLog {
3333
}
3434
}
3535

36-
private fun logSpansDetails(text: Spanned): String {
36+
@JvmStatic fun logSpansDetails(text: Spanned): String {
3737
val spans = text.getSpans(0, text.length, Any::class.java)
3838
val spansList = Arrays.asList<Any>(*spans)
3939

@@ -117,4 +117,4 @@ class AztecLog {
117117
return TextUtils.join("", Collections.nCopies(count, char))
118118
}
119119
}
120-
}
120+
}

aztec/src/main/kotlin/org/wordpress/aztec/watchers/EnterPressedWatcher.kt

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)