Prevent Char-to-code crash (#6392)

This commit is contained in:
SomeTroglodyte 2022-03-21 20:09:01 +01:00 committed by GitHub
parent cf21ade76e
commit 130fd653a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,7 +64,15 @@ data class KeyCharAndCode(val char: Char, val code: Int) {
val UNKNOWN = KeyCharAndCode(Input.Keys.UNKNOWN)
/** mini-factory for control codes - case insensitive */
fun ctrl(letter: Char) = KeyCharAndCode(Char(letter.code and 31), 0)
fun ctrl(letter: Char) = KeyCharAndCode(Char(
try {
letter.code and 31
} catch (ex: NoSuchMethodError) {
// Seems to happen on some Ubuntu systems
@Suppress("DEPRECATION")
letter.toInt() and 31
}
), 0)
/** mini-factory for control codes from keyCodes */
fun ctrlFromCode(keyCode: Int): KeyCharAndCode {