# gpui: Add \`cx.intercept_keystrokes\` API to intercept keystrokes before action dispatch \(\#34084\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 9b63ba6205be428e4fbf18bf411c1f617b6e4398

Requested commit: 9b63ba6205be428e4fbf18bf411c1f617b6e4398

Commit: 9b63ba6205be428e4fbf18bf411c1f617b6e4398

Tree: 29b8ff5b75ef9e54c7b9f39fe38f53bfc9583a20

Author: Ben Kunkle

Committer: GitHub

## Message

```
gpui: Add `cx.intercept_keystrokes` API to intercept keystrokes before action dispatch (#34084)

Closes #ISSUE

`cx.intercept_keystrokes` functions as a sibling API to
`cx.observe_keystrokes`. Under the hood the two API's are basically
identical, however, `cx.observe_keystrokes` runs _after_ all event
dispatch handling (including action dispatch) while
`cx.intercept_keystrokes` runs _before_. This allows for
`cx.stop_propagation()` calls within the `cx.intercept_keystrokes`
callback to prevent action dispatch.

The motivating example usage behind this API is also included in this
PR. It is used as part of a keystroke input component that needs to
intercept keystrokes before action dispatch to display them.

cc: @mikayla-maki 

Release Notes:

- N/A *or* Added/Fixed/Improved ...
```

## Parents

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

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