@@ -48,6 +48,8 @@ import android.view.MotionEvent
4848import android.view.View
4949import android.view.WindowManager
5050import android.view.inputmethod.BaseInputConnection
51+ import android.view.inputmethod.EditorInfo
52+ import android.view.inputmethod.InputConnection
5153import android.widget.CheckBox
5254import android.widget.EditText
5355import android.widget.Toast
@@ -70,6 +72,7 @@ import org.wordpress.aztec.handlers.ListHandler
7072import org.wordpress.aztec.handlers.ListItemHandler
7173import org.wordpress.aztec.handlers.PreformatHandler
7274import org.wordpress.aztec.handlers.QuoteHandler
75+ import org.wordpress.aztec.ime.EditorInfoUtils
7376import org.wordpress.aztec.plugins.IAztecPlugin
7477import org.wordpress.aztec.plugins.IToolbarButton
7578import org.wordpress.aztec.source.Format
@@ -291,6 +294,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
291294
292295 private var focusOnVisible = true
293296
297+ var inputConnection: InputConnection ? = null
298+ var inputConnectionEditorInfo: EditorInfo ? = null
299+
294300 interface OnSelectionChangedListener {
295301 fun onSelectionChanged (selStart : Int , selEnd : Int )
296302 }
@@ -660,6 +666,36 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
660666 }
661667 }
662668
669+ override fun onCreateInputConnection (outAttrs : EditorInfo ) : InputConnection {
670+ // initialize inputConnectionEditorInfo
671+ if (inputConnectionEditorInfo == null ) {
672+ inputConnectionEditorInfo = outAttrs
673+ }
674+
675+ // now init the InputConnection, or replace if EditorInfo contains anything different
676+ if (inputConnection == null || ! EditorInfoUtils .areEditorInfosTheSame(outAttrs, inputConnectionEditorInfo!! )) {
677+ // we have a new InputConnection to create, save the new EditorInfo data and create it
678+ // we make a copy of the parameters being received, because super.onCreateInputConnection may make changes
679+ // to EditorInfo params being sent to it, and we want to preserve the same data we received in order
680+ // to compare.
681+ // (see https://android.googlesource.com/platform/frameworks/base/+/jb-mr0-release/core/java/android/widget/
682+ // TextView.java#5404)
683+ inputConnectionEditorInfo = EditorInfoUtils .copyEditorInfo(outAttrs)
684+ val localInputConnection = super .onCreateInputConnection(outAttrs)
685+ if (localInputConnection == null ) {
686+ // in case super returns null, let's just observe the base implementation, no need to make
687+ // an InputConnectionWrapper of a null target
688+ return localInputConnection
689+ }
690+ // if non null, wrap the new InputConnection around our wrapper
691+ // inputConnection = AztecTextInputConnectionWrapper(localInputConnection, this)
692+ inputConnection = localInputConnection
693+ }
694+
695+ // returnn the existing inputConnection
696+ return inputConnection!!
697+ }
698+
663699 override fun onRestoreInstanceState (state : Parcelable ? ) {
664700 disableTextChangedListener()
665701
0 commit comments