Skip to content

Commit

Permalink
Properly support codepoints outside the BMP; more robust autotype
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepav committed Jun 1, 2024
1 parent 2d04873 commit 46bd5de
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions js/guided-typing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ const STORAGE_KEY = "guided-typing-story";
const DEFAULT_MDTEXT = `
# First Time Instructions
Click on the document icon<img alt="document" src="img/document-icon.png"
style="width: 20px; vertical-align: -0.2em; margin-left: 0.5ch;">
at the top right of the page to edit your story, or click on this text to
see how typing works.
Click on the document icon 🗎 at the top right of the page to edit your story,
or click on this text to see how typing works.
`;

let keyboard = new DisplayKeyboard('US_QWERTY');
Expand Down Expand Up @@ -124,16 +122,18 @@ function processTextInput(textarea, expandedText, successCheck, keyboard, inhibi
} else {
textarea.style.removeProperty("color");
successCheck.style.removeProperty("display");
const nextChar = expandedText[t.length];
const nextChar = String.fromCodePoint(expandedText.codePointAt(t.length));
const keys = keyboard.keysForChar(nextChar);
if (keys) // the keyboard can produce this character
keyboard.highlightKeys(keys);
else {
keyboard.highlightKeys();
if (!inhibitAutofill) { // type it for the user
textarea.disabled = true;
setTimeout(() => {
textarea.value += nextChar;
processTextInput(textarea, expandedText, successCheck, keyboard);
textarea.disabled = false;
textarea.focus();
}, 250);
}
}
Expand Down

0 comments on commit 46bd5de

Please sign in to comment.