Skip to content

Commit

Permalink
bug fixed on fc when unicode surrogate paris (emoji characters) is en…
Browse files Browse the repository at this point in the history
…tered.
  • Loading branch information
jrywu committed Jul 19, 2015
1 parent 826e66a commit 4a40657
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
21 changes: 16 additions & 5 deletions LimeStudio/app/src/main/java/net/toload/main/hd/LIMEService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1355,15 +1355,19 @@ && translateKeyDown(keyCode, event)) {
return super.onKeyUp(keyCode, event);
}


/**
* Helper function to commit any text being composed in to the editor.
*/
private void commitTyped(InputConnection ic) {
if (DEBUG)
Log.i(TAG, "commitTyped()");
try {
if (mComposing.length() > 0 //denotes composing just finished
|| (selectedCandidate != null && !selectedCandidate.isComposingCodeRecord() &&!selectedCandidate.isEnglishSuggestionRecord())) { // commit selected candidate if it is not the composing text. '15,6,4 Jeremy
if ( (mComposing.length() > 0 //denotes composing just finished
|| (selectedCandidate != null && !selectedCandidate.isComposingCodeRecord() )) // commit selected candidate if it is not the composing text. '15,6,4 Jeremy
&& selectedCandidate!=null
&&!selectedCandidate.isEnglishSuggestionRecord()
&&!LIMEUtilities.isUnicodeSurrogate(selectedCandidate.getWord()) ) { //check if it's surrogate characters (emoji) '15,7,19 Jeremy

if (!mEnglishOnly) { //Jeremy '12,4,29 use mEnglishOnly instead of onIM
if (selectedCandidate != null && selectedCandidate.getWord() != null
Expand Down Expand Up @@ -1484,8 +1488,9 @@ private void commitTyped(InputConnection ic) {
clearComposing(false);
updateRelatedPhrase(false);

SearchSrv.learnRelatedPhraseAndUpdateScore(committedCandidate);

if(committedCandidate != null && committedCandidate.getWord() != null){
SearchSrv.learnRelatedPhraseAndUpdateScore(committedCandidate);
SearchSrv.getCodeListStringFromWord(committedCandidate.getWord()); //do reverse lookup and display notification if required.
}

Expand All @@ -1504,8 +1509,14 @@ private void commitTyped(InputConnection ic) {
}


}else if(selectedCandidate.isEnglishSuggestionRecord()){ //Jeremy '15,7,16
ic.commitText(selectedCandidate.getWord(), selectedCandidate.getWord().length()) ;
}else if(selectedCandidate!=null
&& selectedCandidate.isEnglishSuggestionRecord() ){
ic.commitText(selectedCandidate.getWord(), selectedCandidate.getWord().length());
clearComposing(false);
}else if(selectedCandidate!=null &&
LIMEUtilities.isUnicodeSurrogate(selectedCandidate.getWord())){ //Jeremy '15,7,16
ic.commitText(selectedCandidate.getWord(), 1);
clearComposing(false);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
public class LIMEUtilities {
static final String TAG = "LIMEUtilities";
static final boolean DEBUG = false;

public static boolean isUnicodeSurrogate(String word){ // emoji icons are within these surrogate areas
if(word!=null && word.length()==2 ){
char[] chArray = word.toCharArray();
return Character.isSurrogatePair(chArray[0],chArray[1]);
}
return false;

}

public static File isFileNotExist(String filepath){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2164,9 +2164,9 @@ private Pair<String, String> expandDualCode(String code, String keytablename) {
final boolean tonePresent = dualcode.matches(".+[3467 ].*"); // Tone symbols present in any locoation except the first character
final boolean toneNotLast = dualcode.matches(".+[3467 ].+"); // Tone symbols present in any locoation except the first and last character

if (searchNoToneCode) { //noToneCode (phonetic comibnation without tones) is present
if (searchNoToneCode) { //noToneCode (phonetic combination without tones) is present
if (tonePresent) {
//LD phrase if tone symbols present but not in last character or in last character but the lenth > 4 (phonetic combinations never has length >4)
//LD phrase if tone symbols present but not in last character or in last character but the length > 4 (phonetic combinations never has length >4)
if (toneNotLast || (dualcode.length() > 4))
noToneCode = dualcode.replaceAll("[3467 ]", "");

Expand Down

0 comments on commit 4a40657

Please sign in to comment.