Add in_preview boolean context for keybindings
#61765
krawitzzZ
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Body
What are you proposing?
Add an
in_previewboolean context to Zed's key binding system that indicates when the current editor is in preview mode. This would allow users to create context-specific keybindings that only apply to preview tabs.Why does this matter?
Currently, Zed has a preview tab system where files opened from the project panel or via "go to definition" automatically open in preview mode (displayed with italic tab names). However, there is no way to create keybindings that are specific to when an editor is in preview mode.
This feature would enable users to:
qto close the tab)Without this, users cannot create context-specific bindings like
Editor && in_preview, which limits customization options for a commonly used feature.Are there any examples or context?
VS Code Comparison:
VS Code has a similar feature with
workbench.editor.enablePreviewand exposes anisPreviewcontext for keybindings. Users can bind keys like:{ "key": "q", "command": "workbench.action.closeActiveEditor", "when": "editorTextFocus && isPreview" }Zed's Current State:
Panestruct tracks preview state viapreview_item_iddev:OpenKeyContextViewcommand shows active contexts, so users could verify the new contextmenu,renaming,in_snippet,showing_completions, etc.Example Use Case:
With this feature, users could add to their
settings.json:{ "keybindings": [{ "context": "Editor && in_preview", "bindings": { "q": "pane::CloseActiveItem" } }] }This would allow pressing
qto close preview tabs (like clicking a file from the project panel or following "go to definition"), while regular tabs would remain unaffected.Possible approach
The implementation would be a small addition to the
key_context_internal()method insrc/editor.rs. The editor would check if it is the preview item in its containing pane and add thein_previewcontext to the key context.The logic:
window.current_view()self.workspace()workspace.pane_for_item_id()(public method)pane.is_active_preview_item()"in_preview"to the key contextThis is a minimal change (~9 lines of code) that follows existing patterns in Zed's codebase for boolean contexts.
All reactions