Emoji backspace fix

This commit is contained in:
Francisco Hodge 2018-08-24 00:40:54 -04:00
parent ad17363173
commit 30603e76b5
4 changed files with 17 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "simple-keyboard",
"version": "2.3.22",
"version": "2.3.23",
"description": "On-screen Virtual Keyboard",
"main": "build/index.js",
"scripts": {

View File

@ -74,9 +74,20 @@ class Utilities {
let output = input;
let newLineOnEnter = options.newLineOnEnter;
if(button === "{bksp}" && output.length > 0)
output = output.slice(0, -1);
else if(button === "{space}")
if(button === "{bksp}" && output.length > 0){
/**
* Emojis are made out of two characters, so we must take a custom approach to trim them.
* For more info: https://mathiasbynens.be/notes/javascript-unicode
*/
let lastTwoChars = output.slice(-2);
let emojiMatched = lastTwoChars.match(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g);
if(emojiMatched){
output = output.slice(0, -2);
} else {
output = output.slice(0, -1);
}
} else if(button === "{space}")
output = output + ' ';
else if(button === "{tab}")
output = output + "\t";