From 4a40657e307e648eeb159cd7973cb57f53c442e2 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Sun, 19 Jul 2015 17:40:20 +0800 Subject: [PATCH] bug fixed on fc when unicode surrogate paris (emoji characters) is entered. --- .../java/net/toload/main/hd/LIMEService.java | 21 ++++++++++++++----- .../toload/main/hd/global/LIMEUtilities.java | 9 ++++++++ .../net/toload/main/hd/limedb/LimeDB.java | 4 ++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/LimeStudio/app/src/main/java/net/toload/main/hd/LIMEService.java b/LimeStudio/app/src/main/java/net/toload/main/hd/LIMEService.java index 7c325596..567a96a6 100644 --- a/LimeStudio/app/src/main/java/net/toload/main/hd/LIMEService.java +++ b/LimeStudio/app/src/main/java/net/toload/main/hd/LIMEService.java @@ -1355,6 +1355,7 @@ && translateKeyDown(keyCode, event)) { return super.onKeyUp(keyCode, event); } + /** * Helper function to commit any text being composed in to the editor. */ @@ -1362,8 +1363,11 @@ 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 @@ -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. } @@ -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(); diff --git a/LimeStudio/app/src/main/java/net/toload/main/hd/global/LIMEUtilities.java b/LimeStudio/app/src/main/java/net/toload/main/hd/global/LIMEUtilities.java index 89a98e42..0c95d4d3 100644 --- a/LimeStudio/app/src/main/java/net/toload/main/hd/global/LIMEUtilities.java +++ b/LimeStudio/app/src/main/java/net/toload/main/hd/global/LIMEUtilities.java @@ -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){ diff --git a/LimeStudio/app/src/main/java/net/toload/main/hd/limedb/LimeDB.java b/LimeStudio/app/src/main/java/net/toload/main/hd/limedb/LimeDB.java index ed3a307f..ed9fb092 100644 --- a/LimeStudio/app/src/main/java/net/toload/main/hd/limedb/LimeDB.java +++ b/LimeStudio/app/src/main/java/net/toload/main/hd/limedb/LimeDB.java @@ -2164,9 +2164,9 @@ private Pair 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 ]", "");