5 ms·
e.metaKey || (e.ctrlKey && !e.altKey) seems to me like an exceptionally strange choice. Why not an exclusive-or? The thing they want to avoid is a false-positi
by thenewwazoo 5y ago
e.metaKey || (e.ctrlKey && !e.altKey)
seems to me like an exceptionally strange choice. Why not an exclusive-or? The thing they want to avoid is a false-positive on both being pressed, so test for that directly.
- LordDragonfang 5y agoe.metaKey is the `⌘Command` key on Mac (used for the save shortcut), an entirely different key than the ones involved in the bug. Also, Javascript doesn't have a logical xor operator, so trying to do that would potentially reduce readability.
- joshuaissac 5y ago> Javascript doesn't have a logical xor operator x != y
- dhosek 5y agoAlthough with the looseness around booleans in JS, I'd imagine that you might need to do something more like `(x==true) != (y==true)`
- LordDragonfang 5y agoA common hack, and that's where the "potentially reduce readability" caveat comes in.
- smlckz 5y ago> Also, Javascript doesn't have a logical xor operator, so trying to do that would potentially reduce readability. I also didn't know about any operator to logically xor two boolean variables (thought about (ab)using JavaScript's implicit type conversion mechanisms: `x ^ y`), and then I learnt that `!=` works fine as a logical xor for booleans. Tada! I don't know how much readability is reduced by this.
- zamadatix 5y agoWouldn't using XOR trigger a save on Alt + S? Unless I'm missing something with why the meta portion should have the XOR here instead.
- shkkmo 5y agoThe only place XOR could be used is to replace the OR. As you say, replacing the AND NOT with an XOR would supress Alt + s. Even replacing the OR with XOR is not obviously an improvement as it is not clear that we know what the correct behavior would be in the edge case where a keyboard event is emitted with both the control and command flags set.