adobe/brackets — pull request #4110 by njx (2013-06-05 23:33:09+00:00)
Title: REVIEW ONLY: Add ability to create multiple global key handlers

This is an alternate fix for #3975. It creates a more general mechanism for dealing with multiple global capture handlers for keydown.

I think this is a cleaner fix than #4032, and it has the advantage that we can also use this same mechanism to simplify the nested-dialog key handling in Dialogs.js. However, it is somewhat more invasive (though I don't think it's necessarily more risky than #4032 if we can convince ourselves that the logic is correct).

The semantics of these new global keydown handlers is a bit tricky. The idea is that you can install multiple global keydown handlers, with the last-added one running first. Any of these handlers can return true in order to indicate that it handled the key. However, this does *not* have the same effect as the usual event `stopPropagation()`/`preventDefault()`; all it does is prevent the other global keydown handlers (including KeyBindingManager itself) from running. The desired intention is that this is the way modal/semi-modal key handling should work: only one modal should get to deal with the key, but it should be able to decide that the key should go through normal event handling (bypassing other modals further down the stack, including ordinary key bindings).

I tested various cases to try to verify that this is working properly:
* the nested dialogs in ExtensionManager
* code hints without Emmet installed--tested that up/down arrows, Enter and Esc work as expected while code hints are up, and after they're dismissed nothing unusual happens
* code hints with Emmet installed--tested that this actually fixed the original bug :)