JetBrains: Escape inside the web view with a dropdown open should not close the window
Created by: philipp-spiess
Close #37313 (closed)
We don't want to close the popup while a dropdown is opened but instead just want to close the dropdown. To do this, we need to defer the decision making for when to close something into the web view (since this is the only place that knows if dropdown are open).
Ideally we could rely on event bubbling to have the escape event not propagate to the document root when a children handles the event. Unfortunately we can't do this here since we do not control the dropdown implementation in CodeMirror. Since this does not cancel the propagation, we'll need to manually find out if a dropdown is open or not (a behavior that we have already implemented for the arrow up/down navigation).
We also need to make sure to attach event handlers in capture
mode, This makes it so that our event listeners are called before the React tree can react (he-he) to the changes. This is necessary because otherwise the dropdown already appeared closed by the time we get a callback. The capture mode does bypass all event bubbling cancellation (because the capture phase happens before the bubble phase) which means that we can also not rely on stopPropagation
for the event handlers we do control.
Test plan
Manually tested the changes:
https://user-images.githubusercontent.com/458591/176447188-d59a7cb6-dbc9-44b2-ad72-69f2648b5c9b.mov
App preview:
Check out the client app preview documentation to learn more.