aboutsummaryrefslogtreecommitdiff
path: root/xP
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-12 16:43:13 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-12 16:45:29 +0200
commita61789637a5af03b06655c9ce03a92ddd57fe383 (patch)
tree5e62dbc38346b90b40ed8887719e95935f574362 /xP
parent8968100a28256084b444899128a775b794b155e1 (diff)
downloadxK-a61789637a5af03b06655c9ce03a92ddd57fe383.tar.gz
xK-a61789637a5af03b06655c9ce03a92ddd57fe383.tar.xz
xK-a61789637a5af03b06655c9ce03a92ddd57fe383.zip
xP: deal with macOS/Blink for good
Diffstat (limited to 'xP')
-rw-r--r--xP/public/xP.js25
1 files changed, 18 insertions, 7 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js
index 3344a1f..2c4932b 100644
--- a/xP/public/xP.js
+++ b/xP/public/xP.js
@@ -132,13 +132,9 @@ class RelayRpc extends EventTarget {
function utf8Encode(s) { return new TextEncoder().encode(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) {
- // This method of detection only works with Blink browsers, as of writing.
- return event.altKey && !event.metaKey &&
- (navigator.userAgentData?.platform === 'macOS') === event.ctrlKey
+ return (event.altKey || event.escapePrefix) &&
+ !event.metaKey && !event.ctrlKey
}
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 => {
+ 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))
return
@@ -874,4 +885,4 @@ document.addEventListener('keydown', event => {
}
event.preventDefault()
-})
+}, true)