From c20c5a8d4c29f52075a157098cf8d7192a45ac36 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Fri, 13 Aug 2010 13:29:49 -0700 Subject: Fixes for correction mode - reliably show the corrections when tapping on a word. Also, continue to show the corrections when user keeps replacing the word repeatedly with different corrections from the suggestion strip. There were problems with tapping suggestions quickly or tapping the same suggestion more than once (same length). Also fixes Bug: 2852891 - Text suggestion appears incorrectly when selecting text that's not a whole word. Changed the TextEntryState states to an enum type instead of int. Needed it to show the states for debugging purposes. --- .../com/android/inputmethod/latin/EditingUtil.java | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/EditingUtil.java') diff --git a/java/src/com/android/inputmethod/latin/EditingUtil.java b/java/src/com/android/inputmethod/latin/EditingUtil.java index 0c87f8d58..be31cb787 100644 --- a/java/src/com/android/inputmethod/latin/EditingUtil.java +++ b/java/src/com/android/inputmethod/latin/EditingUtil.java @@ -16,12 +16,12 @@ package com.android.inputmethod.latin; -import java.util.regex.Pattern; - import android.view.inputmethod.ExtractedText; import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; +import java.util.regex.Pattern; + /** * Utility methods to deal with editing text through an InputConnection. */ @@ -203,4 +203,27 @@ public class EditingUtil { return null; } } + + /** + * Checks if the cursor is touching/inside a word or the selection is for a whole + * word and no more and no less. + * @param range the Range object that contains the bounds of the word around the cursor + * @param start the start of the selection + * @param end the end of the selection, which could be the same as the start, if text is not + * in selection mode + * @return false if the selection is a partial word or straddling multiple words, true if + * the selection is a full word or there is no selection. + */ + public static boolean isFullWordOrInside(Range range, int start, int end) { + // Is the cursor inside or touching a word? + if (start == end) return true; + + // Is it a selection? Then is the start of the selection the start of the word and + // the size of the selection the size of the word? Then return true + if (start < end + && (range.charsBefore == 0 && range.charsAfter == end - start)) { + return true; + } + return false; + } } -- cgit v1.2.3-83-g751a