Skip to content

Instantly share code, notes, and snippets.

@ShanonJackson
Created May 9, 2020 05:26
Show Gist options
  • Save ShanonJackson/32ff461c18d82af64687cf0c30623cbb to your computer and use it in GitHub Desktop.
Save ShanonJackson/32ff461c18d82af64687cf0c30623cbb to your computer and use it in GitHub Desktop.
// 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