Created
May 9, 2020 05:26
-
-
Save ShanonJackson/32ff461c18d82af64687cf0c30623cbb to your computer and use it in GitHub Desktop.
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
// https://dmitripavlutin.com/what-every-javascript-developer-should-know-about-unicode/#24-surrogate-pairs | |
const isSurrogate = (code) => 0xd800 <= code && code <= 0xdfff; | |
/* Modify our onKeyDown Backspace Handler slightly... */ | |
if (e.keyCode === Keycodes.BACKSPACE) { | |
if (start === 0) return; | |
const charsToRemove = isSurrogate(value.charCodeAt(start - 1)) ? 2 : 1; | |
return insertString("", { start: start - charsToRemove, end: start }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment