# keymap_editor: Remove redundant parentheses when displaying keymap context \(\#50906\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 74ad75843eaeb74ab4a84262188ef7aa9fc78666

Requested commit: 74ad75843eaeb74ab4a84262188ef7aa9fc78666

Commit: 74ad75843eaeb74ab4a84262188ef7aa9fc78666

Tree: f50576ea5cd3e939b95183bcc503b02dde3792c3

Author: Dong

Committer: GitHub

## Message

```
keymap_editor: Remove redundant parentheses when displaying keymap context (#50906)

Closes #34976

## Root Cause

The current implementation of `fmt::Display` in
`KeyBindingContextPredicate` hardcodes a parentheses around `And` and
`Or` cases. Causing the text displayed on the keymap editor to have
nested parentheses.

This PR refactors the display logic and make the parentheses added only
when there's nested operator.

## As is/ To be

As is | To be
--- | ---	
<img width="800" height="1101" alt="Screenshot 2026-03-06 at 15 07 10"
src="https://github.com/user-attachments/assets/33b4366d-4d16-48db-9cc6-b79d6cc7ddc7"
/> | <img width="800" height="977" alt="Screenshot 2026-03-06 at 14 54
57"
src="https://github.com/user-attachments/assets/3d5ed38d-949d-4265-8fad-e29250c3a285"
/>

## Test coverage

<img width="800" height="916" alt="Screenshot 2026-03-06 at 15 00 42"
src="https://github.com/user-attachments/assets/5846b908-5c86-48a7-919e-a7ae198484a8"
/>



Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- keymap_editor: Remove redundant parentheses when displaying keymap
context

---------

Co-authored-by: Ben Kunkle <ben@zed.dev>
```

## Parents

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

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