Skip to content

Conversation

@FloppyDisco
Copy link
Contributor

@FloppyDisco FloppyDisco commented Oct 17, 2025

I love keybindings.

I spend way to much time thinking about them.

I also REALLY like working in Zed.

so far, however, I have found the key context system in Zed to be less flexible than in VSCode.
the HUGE context that is available in VSCode helps you create keybindings for very specific targeted scenarios.

the tree like structure of the Zed key context means you loose some information as focus moves throughout the application.
For example, it is not currently possible to create a keybinding in the editor that will only work when one of the Docks is open, or if a specific dock is open.

this would be useful in implementing solutions to ideas like #24222
we already have an action for moving focus to the dock, and we have an action for opening/closing the dock, but to my knowledge (very limited lol) we cannot determine if that dock is open unless we are focused on it.

I think it is possible to create a more flexible key binding system by adding more context information to the higher up context ancestors.
while:

Workspace right_dock=GitPanel
    Dock
        GitPanel
            Editor

may seem redundant, it actually communicates fundamentally different information than:

Workspace right_dock=GitPanel
    Pane
        Editor

the first says "the GitPanel is in the right hand dock AND IT IS FOCUSED",
while the second means "Focus is on the Editor, and the GitPanel just happens to be open in the right hand dock"

This change adds a new set of identifiers to the Workspace key_context that will indicate which docks are open and what is the specific panel that is currently visible in that dock.

examples:

  • left_dock=ProjectPanel
  • bottom_dock=TerminalPanel
  • right_dock=GitPanel

in my testing the following types of keybindings seem to be supported with this change:

// match for any value of the identifier
"context": "Workspace && bottom_dock"
"context": "Workspace && !bottom_dock"
// match only a specific value to an identifier
"context": "Workspace && bottom_dock=TerminalPanel"
// match only in a child context if the ancestor workspace has the correct identifier
"context": "Workspace && !bottom_dock=DebugPanel > Editor"

some screen shots of the context matching in different circumstances:
Screenshot 2025-10-16 at 23 20 34
Screenshot 2025-10-16 at 23 20 57
Screenshot 2025-10-16 at 23 21 37
Screenshot 2025-10-16 at 23 21 52
Screenshot 2025-10-16 at 23 22 38

the persistent_name values for ProjectPanel and OutlinePanel needed to be updated to not have a space in them in order to pass the Identifier check. all the other Panels already had names that did not include spaces, so it just makes these conform with the other ones.

I think this is a great place to start with adding more context identifiers and i think this type of additional information will make it possible to create really dynamic keybindings!

Release Notes:

  • Workspace key context now includes the state of the 3 docks

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 17, 2025
impl Panel for OutlinePanel {
fn persistent_name() -> &'static str {
"Outline Panel"
"OutlinePanel"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: those 2 persistent_name changes spoil the DB restoration, at least the first time the new version is out.

Seems redundant to do?

@ConradIrwin
Copy link
Member

This makes sense to me, but as Kirill points out we can't change the persistant_name. I'd suggest adding a second method (that can default to the first) for this identifier.

@FloppyDisco
Copy link
Contributor Author

@ConradIrwin
If I'm understanding the feedback here and I have read the docs correctly:

There is a SQLite DB that handles the session restoration when the app is opened, and the table that refers to these panels uses persistent_name as the identifier?

What sort of session information is tied the Project Panel and the Outline Panel?

Wouldn't it just be like the display width?

Is there no way of running migrations on this DB?

I'm just thinking out loud here.

I contemplated creating a new method on the Panels, but changing these two to match all the other panels seemed like the smaller change.

I can create a new method that will just return a key context identifier for the Panel. Give me a bit to work on it.

@FloppyDisco FloppyDisco force-pushed the add-dock-state-to-workspace-context branch from 7a5f9bc to 857450e Compare October 18, 2025 04:26
@FloppyDisco FloppyDisco force-pushed the add-dock-state-to-workspace-context branch from 857450e to 8a16d31 Compare October 18, 2025 04:43
@FloppyDisco
Copy link
Contributor Author

@ConradIrwin

alrighty,

this PR now includes a new method panel_key()

this returns the *_PANEL_KEY const for each of the Panels.
this feels more appropriate than using the persistent_name()

let me know what you think.

@ConradIrwin
Copy link
Member

Sounds good! It would also be possible to write a migration to do this, but I think there are two different things happening here.

@ConradIrwin ConradIrwin enabled auto-merge (squash) October 20, 2025 15:27
auto-merge was automatically disabled October 20, 2025 17:57

Head branch was pushed to by a user without write access

@FloppyDisco
Copy link
Contributor Author

@ConradIrwin
sorry. i saw some tests didn't pass for formatting so i pushed a commit for cargo fmt and it removed auto-merge.

@FloppyDisco
Copy link
Contributor Author

Release Notes:

  • Workspace key context now includes the state of the 3 docks

@ConradIrwin ConradIrwin enabled auto-merge (squash) October 20, 2025 18:01
@ConradIrwin
Copy link
Member

thanks for fixing it!

@ConradIrwin ConradIrwin merged commit 057c3c1 into zed-industries:main Oct 20, 2025
22 checks passed
ConradIrwin pushed a commit that referenced this pull request Oct 28, 2025
Release Notes:

- Pane key context now includes 'buffer_search_deployed' identifier

The goal of this PR is to add a new identifier in the key context that
will let the user target when the BufferSearchBar is deployed even if
they are not focused on it.

requested in #36930

Same rational as #40454 this will allow users to make more flexible
keybindings, by including some additional information higher up the key
context tree.

i thought adding this context to `Pane` seemed more appropriate than
`Editor` since `Terminal` also has a `BufferSearchBar`; however, I ran
into some import issues between BufferSearchBar, Search, Pane, and
Workspace which made it difficult to implement adding this context
directly inside `Pane`'s render function.

instead i added a new method called `contributes_context` to
`ToolbarItem` which will allow any toolbar item to add additional
context to the `Pane` level, which feels like it might come in handy.

here are some screen shots of the context being displayed in the Editor
and the Terminal

<img width="1653" height="1051" alt="Screenshot 2025-10-25 at 14 34 03"
src="https://github.com/user-attachments/assets/21c5b07a-8d36-4e0b-ad09-378b12d2ea38"
/>

<img width="1444" height="1167" alt="Screenshot 2025-10-25 at 12 32 21"
src="https://github.com/user-attachments/assets/86afe72f-b238-43cd-8230-9cb59fb93b2c"
/>
tomatitito pushed a commit to tomatitito/zed that referenced this pull request Nov 7, 2025
Release Notes:

- Pane key context now includes 'buffer_search_deployed' identifier

The goal of this PR is to add a new identifier in the key context that
will let the user target when the BufferSearchBar is deployed even if
they are not focused on it.

requested in zed-industries#36930

Same rational as zed-industries#40454 this will allow users to make more flexible
keybindings, by including some additional information higher up the key
context tree.

i thought adding this context to `Pane` seemed more appropriate than
`Editor` since `Terminal` also has a `BufferSearchBar`; however, I ran
into some import issues between BufferSearchBar, Search, Pane, and
Workspace which made it difficult to implement adding this context
directly inside `Pane`'s render function.

instead i added a new method called `contributes_context` to
`ToolbarItem` which will allow any toolbar item to add additional
context to the `Pane` level, which feels like it might come in handy.

here are some screen shots of the context being displayed in the Editor
and the Terminal

<img width="1653" height="1051" alt="Screenshot 2025-10-25 at 14 34 03"
src="https://github.com/user-attachments/assets/21c5b07a-8d36-4e0b-ad09-378b12d2ea38"
/>

<img width="1444" height="1167" alt="Screenshot 2025-10-25 at 12 32 21"
src="https://github.com/user-attachments/assets/86afe72f-b238-43cd-8230-9cb59fb93b2c"
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants