Last active
December 17, 2015 16:49
-
-
Save leob2g/5641974 to your computer and use it in GitHub Desktop.
handleSuggestions function of latin.js in keyboard is modified to handle capitalization of letters in suggestion mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function handleSuggestions(input, suggestions) { | |
function isCapitalized(word) { | |
return word.toLowerCase() !== word; | |
} | |
function capitalize(inputword, suggestionWord) { | |
var result = suggestionWord; | |
for (var j = 0; j < inputword.length; j++) { | |
if (isCapitalized(inputword[j])) { | |
result = result.substring(0, j) + result[j].toUpperCase() | |
+ result.substring(j+1); | |
} | |
} | |
return result; | |
} | |
function wordBeforeCursor() { | |
return inputText.substring(wordStartBeforeCursor(), cursor); | |
} | |
var typedWord = wordBeforeCursor(); | |
if (input !== typedWord || typedWord.length == 0) { | |
//user typing faster than suggestions provided or | |
//the length of typed word is zero | |
keyboard.sendCandidates([]); | |
} else { | |
if (typedWord.toLowerCase() !== typedWord) { | |
//capitalize all of the suggestions comparing to input string | |
for (var i = 0; i < suggestions.length; i++) { | |
suggestions[i] = capitalize(typedWord, suggestions[i]); | |
} | |
} | |
keyboard.sendCandidates(suggestions); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment