Skip to content

Instantly share code, notes, and snippets.

@leob2g
Last active December 17, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leob2g/5641974 to your computer and use it in GitHub Desktop.
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
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