# Fix \`bindings_for_action\` handling of shadowed key bindings \(\#32220\) · gitcafe/zed

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

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

Visibility: public

Requested revision: d801b7b12e02c0bb918e77d68ea7c2f6dba21c7a

Requested commit: d801b7b12e02c0bb918e77d68ea7c2f6dba21c7a

Commit: d801b7b12e02c0bb918e77d68ea7c2f6dba21c7a

Tree: e43e1c37fe8a667f6887bee3cd254c2eca0a1b85

Author: Michael Sloan

Committer: GitHub

## Message

```
Fix `bindings_for_action` handling of shadowed key bindings (#32220)

Fixes two things:

* ~3 months ago [in PR
#26420](https://github.com/zed-industries/zed/pull/26420/files#diff-33b58aa2da03d791c2c4761af6012851b7400e348922d64babe5fd48ac2a8e60)
`bindings_for_action` was changed to return bindings even when they are
shadowed (when the keystrokes would actually do something else).

* For edit prediction keybindings there was some odd behavior where
bindings for `edit_prediction_conflict` were taking precedence over
bindings for `edit_prediction` even when the `edit_prediction_conflict`
predicate didn't match. The workaround for this was #24812. The way it
worked was:

    - List all bindings for the action

- For each binding, get the highest precedence binding with the same
input sequence

- If the highest precedence binding has the same action, include this
binding. This was the bug - this meant that if a binding in the keymap
has the same keystrokes and action it can incorrectly take display
precedence even if its context predicate does not pass.

- Fix is to check that the highest precedence binding is a full match.
To do this efficiently, it's based on an index within the keymap
bindings.

Also adds `highest_precedence_binding_*` variants which avoid the
inefficiency of building lists of bindings just to use the last.

Release Notes:

- Fixed display of keybindings to skip bindings that are shadowed by a
binding that uses the same keystrokes.
- Fixed display of `editor::AcceptEditPrediction` bindings to use the
normal precedence that prioritizes user bindings.
```

## Parents

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

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