xP: deal with macOS/Blink for good
This commit is contained in:
parent
8968100a28
commit
a61789637a
@ -132,13 +132,9 @@ class RelayRpc extends EventTarget {
|
|||||||
function utf8Encode(s) { return new TextEncoder().encode(s) }
|
function utf8Encode(s) { return new TextEncoder().encode(s) }
|
||||||
function utf8Decode(s) { return new TextDecoder().decode(s) }
|
function utf8Decode(s) { return new TextDecoder().decode(s) }
|
||||||
|
|
||||||
// On macOS, the Alt/Option key transforms characters, which basically breaks
|
|
||||||
// all event.altKey shortcuts, so require combining them with Control as well
|
|
||||||
// on that system.
|
|
||||||
function hasShortcutModifiers(event) {
|
function hasShortcutModifiers(event) {
|
||||||
// This method of detection only works with Blink browsers, as of writing.
|
return (event.altKey || event.escapePrefix) &&
|
||||||
return event.altKey && !event.metaKey &&
|
!event.metaKey && !event.ctrlKey
|
||||||
(navigator.userAgentData?.platform === 'macOS') === event.ctrlKey
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const audioContext = new AudioContext()
|
const audioContext = new AudioContext()
|
||||||
@ -826,7 +822,22 @@ document.addEventListener('visibilitychange', event => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// On macOS, the Alt/Option key transforms characters, which basically breaks
|
||||||
|
// all event.altKey shortcuts, so implement Escape prefixing on that system.
|
||||||
|
// This method of detection only works with Blink browsers, as of writing.
|
||||||
|
let lastWasEscape = false
|
||||||
document.addEventListener('keydown', event => {
|
document.addEventListener('keydown', event => {
|
||||||
|
event.escapePrefix = lastWasEscape
|
||||||
|
if (lastWasEscape) {
|
||||||
|
lastWasEscape = false
|
||||||
|
} else if (event.code == 'Escape' &&
|
||||||
|
navigator.userAgentData?.platform === 'macOS') {
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
lastWasEscape = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (rpc.ws == undefined || !hasShortcutModifiers(event))
|
if (rpc.ws == undefined || !hasShortcutModifiers(event))
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -874,4 +885,4 @@ document.addEventListener('keydown', event => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
})
|
}, true)
|
||||||
|
Loading…
Reference in New Issue
Block a user