FEATURE: Accept the flag modal on CTRL + ENTER and CMD + ENTER (PR #13497)

We want to submit the flag modal on pressing CTRL + ENTER and CMD + ENTER.

Here’s how our modals work:

  • Every modal can be dismissed by pressing ESC. This behaviour can be disabled for a specific modal if we need to.
  • Every modal can be submitted by pressing ENTER if the cursor wasn’t on a text area of a form at the moment of pressing.

Now, the flag modal is actually one big form and pressing ENTER doesn’t submit it. I’ve added submitting by CTRL+ENTER but at first it was interfering with the basic modal submitting by ENTER. It’s a pretty tricky thing to fix because we use the keyup event for submitting by ENTER and we need to use the keydown event for submitting with modifiers (because submitting by CMD+ENTER on Macs doesn’t work with keyup).

Eventually, I fixed the problem just by adding a possibility to disable default submitting on ENTER (in the same way as we already have the possibility of disabling dismissing on ESC). Then I disabled default submitting for the flag form and implemented submitting by CTRL+ENTER and CMD+ENTER. This way everything is simple and robust. I did it only for the flag modal but it’ll be easy and safe to add the same behaviour to another modal.


The title of this pull request changed from “FEATURE: Accept the flag modal by CTRL + ENTER and CMD + ENTER” to "FEATURE: Accept the flag modal on CTRL + ENTER and CMD + ENTER