Files
zed/crates/tab_switcher
David Baldwin 46017f9612 Add tab switcher mode similar to vim/helix buffer picker (#47079)
Implements the enhancement requested in #24655 - enables tab switcher to
show all open files across all panes deduped. It's called "follow mode"
because whichever is the active pane is ALWAYS where the file, terminal,
etc will be opened from the tab switcher (not married to this mode
name).

Adds `follow_mode: true` option to `tab_switcher::ToggleAll`. When
enabled:

- **Shows all tabs across panes** - Same file in multiple panes appears
once (deduped by path)
- **Opens in active pane** - Selecting a file opens it in current pane,
creating independent editor instances
- **Moves terminals** - Non-file items (terminals, multibuffers) move to
current pane instead of duplicating
- **Preview & restore** - Navigate with arrow keys / tab to preview,
Escape restores original state

Intended for vim/helix `:buffers` command workflow while respecting
Zed's tab-based paradigm.

### Usage

```json
["tab_switcher::ToggleAll", {"follow_mode": true}]
```

### Implementation

**Preview pattern:** Clone item handles during navigation, clean up on
dismiss
- **Files**: Preview with cloned handle, confirm closes preview and
opens fresh (independent editors)
- **Terminals**: Preview with cloned handle, confirm removes from source
(moves to current pane)

**Key technical details:**
- Ignore workspace events during follow mode to prevent list re-sorting
from preview operations
- Preserve preview tab status on confirm
- Close operations remove from all panes in follow mode
- Remove from source before activating to ensure correct focus
management

### Test Coverage

21 tests total (14 new follow mode tests):
- File behavior: deduplication, independent editors, preview status
preservation, close behavior
- Non-file behavior: terminal movement, focus management, single pane
scenarios
- General: MRU stability, restore on dismiss

### Release Notes

- Added `follow_mode` option to `tab_switcher::ToggleAll` for vim-style
buffer list showing all deduped open files across panes opening in
active pane

## Q&A

**Q: Why not tie this to vim mode?**

A: This feature is different enough from vim/helix buffer behavior that
I opted not to couple them. It is an approximation using Zed's tab
switcher/picker and would take architectural changes to implement real
vim/helix buffers. Additionally, both follow mode and regular tab
switcher mode are useful window/tab management workflows that vim or
non-vim users may want regardless of their editing mode preference.

**Q: How to use this?**

A: For a vim/helix-like workflow:

1. **Bind the follow mode tab switcher** - Add to your keymap:
   ```json
   {
     "context": "Workspace",
     "bindings": {
       "cmd-i": ["tab_switcher::ToggleAll", {"follow_mode": true}]
     }
   }
   ```

2. **Hide the tab bar (optional)** - Add to settings:
   ```json
   {
     "tab_bar": {
       "show": false
     }
   }
   ```

3. **Move tabs to other pane on close (optional)** - Add to your keymap
to join tabs into next pane when closing:
   ```json
   {
     "context": "Pane",
     "bindings": {
       "cmd-w": "pane::JoinIntoNext"
     }
   }
   ```

This makes closing a tab behave more like vim's split closure - items
move to the adjacent pane instead of being closed.

If you find that you'd rather have the tab bar visible, there's a pretty
good chance you don't need/want this feature. Vim/helix don't have
visible tab bars, so this feature is primarily for users who want that
sort of experience where buffers are not tied to a specific split/pane
and closing a split does not impact the available buffers.

## Future Work

A few additional features could make for more complete vim/helix-like
buffer workflow:

**`:bd` (buffer delete) improvements:**
- Should close the buffer from ALL panes, not just the current one
- Current implementation: `workspace::CloseActiveItem` only closes in
current pane
- Needed: New action like `workspace::CloseActiveItemAcrossPanes` and/or
update vim command mapping

**`:q` (quit) improvements:**
- Should close the split/pane while preserving its tabs
- Behavior: merge tabs into next pane (like `pane::JoinIntoNext`),
unless it's the last pane
- Last pane: close the pane and all its items
- Current implementation: `workspace::CloseActiveItem` closes active
item, not the pane
- Needed: New action or pane closure logic that moves tabs before
closing

These are complementary to this feature and can be done as separate PRs.

Release Notes:

- Add `tab_switcher::ToggleUnique` to allow a more vim-like tab
switching experience.
2026-02-05 20:25:20 +00:00
..
2025-10-17 18:58:14 +00:00
2024-03-27 11:15:08 -07:00