# editor: Add in_preview boolean context for keybindings \(\#61777\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 30aea6ac4a566689a37536407054015c43647811

Requested commit: 30aea6ac4a566689a37536407054015c43647811

Commit: 30aea6ac4a566689a37536407054015c43647811

Tree: 5fec75201831b94ded5f78f0d8e1b7951ca3677e

Author: Nikita Demin

Committer: GitHub

## Message

```
editor: Add in_preview boolean context for keybindings (#61777)

# Objective

- Add an `in_preview` context that is available when the current editor
is in preview mode (opened from project panel or go to definition).
- closes https://github.com/zed-industries/zed/discussions/61765

## Solution

- In `editor.rs`, added a check in `key_context()` that detects if the
editor is the active preview item in its pane, and if so, adds
`"in_preview"` to the key context.
- Uses existing `workspace.pane_for_item_id()` and
`pane.is_active_preview_item()` methods — no new APIs introduced.

## Testing

- Added two tests in `editor_tests.rs`:
- `test_in_preview_context_added_when_in_preview_mode` — verifies
`in_preview` is present when editor is set as preview item.
- `test_in_preview_context_not_added_when_not_in_preview_mode` —
verifies `in_preview` is absent for regular (non-preview) tabs.
- Tested on Linux.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Added `in_preview` keybinding context for when an editor is in preview
mode.
```

## Parents

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

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