# Add click out events to GPUI \(\#2659\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/f6b64dc67ab18f60836444c13192764225d96af3)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: f6b64dc67ab18f60836444c13192764225d96af3

Requested commit: f6b64dc67ab18f60836444c13192764225d96af3

Commit: f6b64dc67ab18f60836444c13192764225d96af3

Tree: 08a912419f3784808c5d5f68e68c697ef228f524

Author: Mikayla Maki

Committer: GitHub

## Message

```
Add click out events to GPUI (#2659)

This PR adds a new mouse event type for catching when a click happens
outside of a given region.

This was added because I noticed a 'race condition' between the context
menu and the buttons which deploy a context menu. Buttons use on
an`on_click()` handler to deploy the context menu, but the context menu
was closing itself with an `on_down_out()` handler. This meant that the
order of operations was:

0. Context menu is open
1. User presses down on the button, _outside of the context menu_ 
2. `on_down_out()` is fired, closing the context menu
3. User releases the mouse
4. `click()` is fired, checks the state of the context menu, finds that
it's closed, and so opens it

You can see this behavior demonstrated with this video with a long-click
here:


https://github.com/zed-industries/zed/assets/2280405/588234c3-1567-477f-9a12-9e6a70643527

~~Switching from `on_down_out()` to `on_click_out()` means that the
click handler for the button can close the menu before the context menu
gets a chance to close itself.~~

~~However, GPUI does not have an `on_click_out()` event, hence this
PR.~~

~~Here's an example of the new behavior, with the same long-click
action:~~


https://github.com/zed-industries/zed/assets/2280405/a59f4d6f-db24-403f-a281-2c1148499413

Unfortunately, this `click_out` is the incorrect event for this to
happen on. This PR now adds a mechanism for delaying the firing of a
cancel action so that toggle buttons can signal that this on_down event
should not result in a menu closure.

Release Notes:

* Made context menus deployed from buttons toggle, instead of
hide-and-re-show, visibility on click
```

## Parents

- [167dd1c5d2af0de00ebac1c31910aaf3d6cb8d08](https://git.cafe/gitcafe/zed/commit/167dd1c5d2af0de00ebac1c31910aaf3d6cb8d08?format=markdown)

- [73b0f3b23d126a9f06eec8cbf3fbcd15a4c3745f](https://git.cafe/gitcafe/zed/commit/73b0f3b23d126a9f06eec8cbf3fbcd15a4c3745f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/f6b64dc67ab18f60836444c13192764225d96af3?format=markdown)
