コード例 #1
0
 /**
  * This method works around the issue crbug.com/373934 where Blink does not cancel the composition
  * when we send a commit with the empty text.
  *
  * <p>TODO(aurimas) Remove this once crbug.com/373934 is fixed.
  *
  * @param text Text that software keyboard requested to commit.
  * @return Whether the workaround was performed.
  */
 private boolean maybePerformEmptyCompositionWorkaround(CharSequence text) {
   int selectionStart = Selection.getSelectionStart(mEditable);
   int selectionEnd = Selection.getSelectionEnd(mEditable);
   int compositionStart = getComposingSpanStart(mEditable);
   int compositionEnd = getComposingSpanEnd(mEditable);
   if (TextUtils.isEmpty(text)
       && (selectionStart == selectionEnd)
       && compositionStart != INVALID_COMPOSITION
       && compositionEnd != INVALID_COMPOSITION) {
     beginBatchEdit();
     finishComposingText();
     int selection = Selection.getSelectionStart(mEditable);
     deleteSurroundingText(selection - compositionStart, selection - compositionEnd);
     endBatchEdit();
     return true;
   }
   return false;
 }