Created
January 17, 2023 12:10
-
-
Save bjoerntx/668ea4d2f861c22ff944ac0134d0f4c4 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
// dynamic character array | |
var charCodes = []; | |
// shortcut dictionary | |
var dict = { | |
"TY": "Thanks for your request.", | |
"AQ": "Let me know if you have additional questions.", | |
"MY": "I look forward to meeting you.", | |
"GD": "Have a great day.", | |
"LONG": "This is another longer text.", | |
}; | |
document.getElementById("txTemplateDesignerContainer").addEventListener("keypress", (event) => { | |
// if SPACE is pressed | |
if (event.charCode === 32) { | |
// convert array to string to get typed word | |
var typedWord = String.fromCharCode(...charCodes); | |
// check word in dictionary | |
if (dict[typedWord] != undefined) { | |
// cancel SPACE for TXTextControl | |
event.cancelBubble = true; | |
// select shortcut and replace with long text | |
TXTextControl.inputPosition.getTextPosition(function (startPos) { | |
TXTextControl.select(startPos - typedWord.length, typedWord.length, function () { | |
TXTextControl.selection.setText(dict[typedWord] + " "); | |
}) | |
}) | |
} | |
// reset character array | |
charCodes = []; | |
} else { | |
// add character to array | |
charCodes.push(event.charCode); | |
} | |
}, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment