@@ -35,6 +35,7 @@ import android.os.Parcel
3535import android.os.Parcelable
3636import android.text.Editable
3737import android.text.InputFilter
38+ import android.text.Selection
3839import android.text.Spannable
3940import android.text.SpannableStringBuilder
4041import android.text.Spanned
@@ -50,6 +51,8 @@ import android.view.View
5051import android.view.View.OnLongClickListener
5152import android.view.WindowManager
5253import android.view.inputmethod.BaseInputConnection
54+ import android.view.inputmethod.CompletionInfo
55+ import android.view.inputmethod.CorrectionInfo
5356import android.widget.CheckBox
5457import android.widget.EditText
5558import android.widget.Toast
@@ -116,6 +119,7 @@ import org.wordpress.aztec.watchers.InlineTextWatcher
116119import org.wordpress.aztec.watchers.ParagraphBleedAdjuster
117120import org.wordpress.aztec.watchers.ParagraphCollapseAdjuster
118121import org.wordpress.aztec.watchers.ParagraphCollapseRemover
122+ import org.wordpress.aztec.watchers.SamsungPredictiveEventsWatcher
119123import org.wordpress.aztec.watchers.SuggestionWatcher
120124import org.wordpress.aztec.watchers.TextDeleter
121125import org.wordpress.aztec.watchers.ZeroIndexContentWatcher
@@ -217,6 +221,30 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
217221 }
218222 }
219223
224+ override fun onBeginBatchEdit () {
225+ super .onBeginBatchEdit()
226+ }
227+
228+ override fun onEditorAction (actionCode : Int ) {
229+ super .onEditorAction(actionCode)
230+ }
231+
232+ override fun onPrivateIMECommand (action : String? , data : Bundle ? ): Boolean {
233+ return super .onPrivateIMECommand(action, data)
234+ }
235+
236+ override fun onKeyDown (keyCode : Int , event : KeyEvent ? ): Boolean {
237+ return super .onKeyDown(keyCode, event)
238+ }
239+
240+ override fun onCommitCorrection (info : CorrectionInfo ? ) {
241+ super .onCommitCorrection(info)
242+ }
243+
244+ override fun onCommitCompletion (text : CompletionInfo ? ) {
245+ super .onCommitCompletion(text)
246+ }
247+
220248 private val REGEXP_EMAIL = Regex (" ^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,}$" ,
221249 setOf (RegexOption .DOT_MATCHES_ALL , RegexOption .IGNORE_CASE ))
222250 private val REGEXP_STANDALONE_URL = Regex (" ^(?:[a-z]+:|#|\\ ?|\\ .|/)" , RegexOption .DOT_MATCHES_ALL )
@@ -676,14 +704,41 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
676704 val equalRange = start == 0 && dstart == 0 && end == source.length && dend == source.length
677705
678706 if (equalStringValues && equalRange) {
707+ overrideSamsungPredictiveBehavior = false
679708 // we can't just return a dest, so we need to copy it into a new spannable string
680709 // this will also strip all the internal "service" spans
681710 temp = SpannableStringBuilder (dest)
682- TextUtils .copySpansFrom(dest, 0 , dest.length, Any ::class .java, temp, 0 )
711+ // TextUtils.copySpansFrom(dest, 0, dest.length, Any::class.java, temp, 0)
683712 // copy all the suggestion spans from the source, so we can see underlines
713+ disableCrashPreventerInputFilter()
714+ disableTextChangedListener()
715+ disableMediaDeletedListener()
716+
684717 if (source is Spanned ) {
685718 TextUtils .copySpansFrom(source, 0 , dest.length, SuggestionSpan ::class .java, temp, 0 )
686719 }
720+
721+ val selStart = Selection .getSelectionStart(text)
722+ val selEnd = Selection .getSelectionEnd(text)
723+ val len = text.length
724+
725+ text.clearSpans()
726+ setTextKeepState(temp)
727+
728+ if (selStart >= 0 || selEnd >= 0 ) {
729+ Selection .setSelection(text,
730+ Math .max(0 , Math .min(selStart, len)),
731+ Math .max(0 , Math .min(selEnd, len)))
732+ }
733+
734+
735+ contentChangeWatcher.notifyContentChanged()
736+
737+ temp = null
738+ enableTextChangedListener()
739+ enableMediaDeletedListener()
740+ enableCrashPreventerInputFilter()
741+ overrideSamsungPredictiveBehavior = true
687742 }
688743 }
689744 temp
@@ -749,14 +804,16 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
749804 source
750805 }
751806
752- filters = if (Build .MANUFACTURER == " samsung" && Build .VERSION .SDK_INT == 33 ) {
753- arrayOf(samsungContentReplacementPreventer, emptyEditTextBackspaceDetector)
754- } else if (Build .VERSION .SDK_INT == Build .VERSION_CODES .O || Build .VERSION .SDK_INT == Build .VERSION_CODES .O_MR1 ) {
755- // dynamicLayoutCrashPreventer needs to be first in array as these are going to be chained when processed
756- arrayOf(dynamicLayoutCrashPreventer, emptyEditTextBackspaceDetector)
757- } else {
758- arrayOf(emptyEditTextBackspaceDetector)
759- }
807+ filters =
808+ if (Build .MANUFACTURER == " samsung" && Build .VERSION .SDK_INT == 33 ) {
809+ arrayOf(samsungContentReplacementPreventer, emptyEditTextBackspaceDetector)
810+ } else
811+ if (Build .VERSION .SDK_INT == Build .VERSION_CODES .O || Build .VERSION .SDK_INT == Build .VERSION_CODES .O_MR1 ) {
812+ // dynamicLayoutCrashPreventer needs to be first in array as these are going to be chained when processed
813+ arrayOf(dynamicLayoutCrashPreventer, emptyEditTextBackspaceDetector)
814+ } else {
815+ arrayOf(emptyEditTextBackspaceDetector)
816+ }
760817 }
761818
762819 private fun isCleanStringEmpty (text : CharSequence ): Boolean {
@@ -1901,7 +1958,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
19011958 val html = Format .removeSourceEditorFormatting(parser.toHtml(output), isInCalypsoMode, isInGutenbergMode)
19021959
19031960 val clipboard = context.getSystemService(Context .CLIPBOARD_SERVICE ) as android.content.ClipboardManager
1904- clipboard.primaryClip = ClipData .newHtmlText(" aztec" , output.toString(), html)
1961+ clipboard.setPrimaryClip( ClipData .newHtmlText(" aztec" , output.toString(), html) )
19051962 }
19061963
19071964 // copied from TextView with some changes
0 commit comments