Skip to content

Commit 4455d27

Browse files
authored
Merge pull request #817 from wordpress-mobile/fix/gutenberg-stray-selection-events
[Gutenberg] Bypass selection events until listener is re-enabled
2 parents c83d232 + be7f70e commit 4455d27

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
246246
var commentsVisible = resources.getBoolean(R.bool.comments_visible)
247247

248248
var isInCalypsoMode = true
249+
var isInGutenbergMode = false
249250

250251
var consumeHistoryEvent: Boolean = false
251252

@@ -343,6 +344,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
343344
isInCalypsoMode = isCompatibleWithCalypso
344345
}
345346

347+
fun setGutenbergMode(isCompatibleWithGutenberg: Boolean) {
348+
isInGutenbergMode = isCompatibleWithGutenberg
349+
}
350+
346351
@SuppressLint("ResourceType")
347352
private fun init(attrs: AttributeSet?) {
348353
disableTextChangedListener()
@@ -860,6 +865,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
860865
if (!isViewInitialized) return
861866

862867
if (isOnSelectionListenerDisabled()) {
868+
if (isInGutenbergMode) {
869+
return
870+
}
871+
863872
enableOnSelectionListener()
864873
return
865874
}
@@ -1128,7 +1137,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11281137
val parser = AztecParser(plugins)
11291138

11301139
var cleanSource = CleaningUtils.cleanNestedBoldTags(source)
1131-
cleanSource = Format.removeSourceEditorFormatting(cleanSource, isInCalypsoMode)
1140+
cleanSource = Format.removeSourceEditorFormatting(cleanSource, isInCalypsoMode, isInGutenbergMode)
11321141
builder.append(parser.fromHtml(cleanSource, context))
11331142

11341143
Format.preProcessSpannedText(builder, isInCalypsoMode)
@@ -1538,7 +1547,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15381547
}
15391548
}
15401549

1541-
val html = Format.removeSourceEditorFormatting(parser.toHtml(output), isInCalypsoMode)
1550+
val html = Format.removeSourceEditorFormatting(parser.toHtml(output), isInCalypsoMode, isInGutenbergMode)
15421551

15431552
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager
15441553
clipboard.primaryClip = ClipData.newHtmlText("aztec", output.toString(), html)

aztec/src/main/kotlin/org/wordpress/aztec/source/Format.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ object Format {
5050
}
5151

5252
@JvmStatic
53-
fun removeSourceEditorFormatting(html: String, isCalypsoFormat: Boolean = false): String {
53+
fun removeSourceEditorFormatting(html: String, isCalypsoFormat: Boolean = false, isGutenbergMode: Boolean = false): String {
5454
if (isCalypsoFormat) {
5555
val htmlWithoutSourceFormatting = toCalypsoHtml(html)
5656
val doc = Jsoup.parseBodyFragment(htmlWithoutSourceFormatting.replace("\n", "")).outputSettings(Document.OutputSettings().prettyPrint(false))
5757
return doc.body().html()
5858
} else {
59-
return replaceAll(html, "\\s*<(/?($block)(.*?))>\\s*", "<$1>")
59+
return if (isGutenbergMode) { html } else { replaceAll(html, "\\s*<(/?($block)(.*?))>\\s*", "<$1>") }
6060
}
6161
}
6262

0 commit comments

Comments
 (0)