Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    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.


e.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.


> 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.


> Javascript doesn't have a logical xor operator

x != y


A common hack, and that's where the "potentially reduce readability" caveat comes in.


Although with the looseness around booleans in JS, I'd imagine that you might need to do something more like `(x==true) != (y==true)`


Wouldn'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.


The 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: