@@ -9829,7 +9829,7 @@ private void updateSuggestions() {
98299829 highlightTextDifferences (mSuggestionInfos [i ], spanUnionStart , spanUnionEnd );
98309830 }
98319831
9832- // Add to dictionary item is there a span with the misspelled flag
9832+ // Add to dictionary item if there is a span with the misspelled flag
98339833 if (misspelledSpan != null ) {
98349834 final int misspelledStart = spannable .getSpanStart (misspelledSpan );
98359835 final int misspelledEnd = spannable .getSpanEnd (misspelledSpan );
@@ -9915,7 +9915,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
99159915
99169916 final int spanStart = editable .getSpanStart (suggestionInfo .suggestionSpan );
99179917 final int spanEnd = editable .getSpanEnd (suggestionInfo .suggestionSpan );
9918- if (spanStart < 0 || spanEnd < 0 ) {
9918+ if (spanStart < 0 || spanEnd <= spanStart ) {
99199919 // Span has been removed
99209920 hide ();
99219921 return ;
@@ -9983,14 +9983,14 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
99839983 // way to assign them a valid range after replacement
99849984 if (suggestionSpansStarts [i ] <= spanStart &&
99859985 suggestionSpansEnds [i ] >= spanEnd ) {
9986- // TODO The ExtractEditText should restore these spans in the original text
9987- editable .setSpan (suggestionSpans [i ], suggestionSpansStarts [i ],
9986+ setSpan_internal (suggestionSpans [i ], suggestionSpansStarts [i ],
99889987 suggestionSpansEnds [i ] + lengthDifference , suggestionSpansFlags [i ]);
99899988 }
99909989 }
99919990
99929991 // Move cursor at the end of the replaced word
9993- Selection .setSelection (editable , spanEnd + lengthDifference );
9992+ final int newCursorPosition = spanEnd + lengthDifference ;
9993+ setCursorPosition_internal (newCursorPosition , newCursorPosition );
99949994 }
99959995
99969996 hide ();
@@ -11463,6 +11463,22 @@ protected void replaceText_internal(int start, int end, CharSequence text) {
1146311463 ((Editable ) mText ).replace (start , end , text );
1146411464 }
1146511465
11466+ /**
11467+ * Sets a span on the specified range of text
11468+ * @hide
11469+ */
11470+ protected void setSpan_internal (Object span , int start , int end , int flags ) {
11471+ ((Editable ) mText ).setSpan (span , start , end , flags );
11472+ }
11473+
11474+ /**
11475+ * Moves the cursor to the specified offset position in text
11476+ * @hide
11477+ */
11478+ protected void setCursorPosition_internal (int start , int end ) {
11479+ Selection .setSelection (((Editable ) mText ), start , end );
11480+ }
11481+
1146611482 @ ViewDebug .ExportedProperty (category = "text" )
1146711483 private CharSequence mText ;
1146811484 private CharSequence mTransformed ;
0 commit comments