Skip to content

editor: Skip untitled buffers when saving a multi-buffer - #61380

Merged
nathansobo merged 1 commit into
zed-industries:mainfrom
IbrahimKhan12:fix/save-multibuffer-with-untitled-buffer
Jul 24, 2026
Merged

editor: Skip untitled buffers when saving a multi-buffer#61380
nathansobo merged 1 commit into
zed-industries:mainfrom
IbrahimKhan12:fix/save-multibuffer-with-untitled-buffer

Conversation

@IbrahimKhan12

Copy link
Copy Markdown
Contributor

Closes #60041.

Summary

When Project Search results contain both a saved file and an untitled buffer, running workspace: reload did nothing (quitting hit the same path). The log showed:

ERROR [.../workspace.rs] buffer doesn't have a file

Root cause

The Project Search results view is an Editor over a multi-buffer, and its Item::save delegates to Editor::save. For a multi-buffer, Editor::save collects every dirty buffer and calls Project::save_buffers. An untitled excerpt has no file, so BufferStore::save_buffer returns Err("buffer doesn't have a file"). That error propagates through Pane::save_itemsave_all_internalprepare_to_close, which then reports the workspace as not ready to close, so reload/quit silently aborts.

A singleton untitled buffer avoids this because Editor::can_save returns false for it (the workspace routes it to save_as); for a multi-buffer, can_save is always true.

Fix

Exclude file-less (untitled) buffers when collecting the buffers to save for a multi-buffer. Untitled buffers can only be written via save_as, so a bulk multi-buffer save now persists the file-backed excerpts and leaves untitled ones untouched. This also addresses the same latent issue in other multi-buffer views (diagnostics, find-all-references) that can excerpt an untitled buffer.

Testing

  • Added test_save_multi_buffer_with_untitled_buffer_skips_untitled in crates/editor/src/items.rs: it builds a multi-buffer over a file-backed buffer and an untitled buffer (both dirty), then asserts save succeeds, the file-backed buffer is persisted, and the untitled buffer stays dirty. Fails before this change (buffer doesn't have a file), passes after.
  • cargo test -p editor --lib save (13 tests) and cargo test -p search --lib project_search (22 tests) pass.
  • ./script/clippy -p editor is clean.

Manual repro (before): new untitled buffer with text → Project Search for a term matching both it and a saved file → workspace: reload → no-op with buffer doesn't have a file in the log. After: reload proceeds.

Release Notes:

  • Fixed workspace: reload and quitting silently doing nothing when Project Search results included an unsaved untitled buffer.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 21, 2026
A multi-buffer such as project search results can excerpt an untitled buffer alongside file-backed ones. `Editor::save` collected every dirty buffer, so saving tried to persist the untitled buffer to disk and failed with "buffer doesn't have a file". That error aborted `prepare_to_close`, making `workspace: reload` (and quit) silently no-op when search results mixed a saved file with an untitled buffer.

Untitled buffers can only be written via `save_as`, so exclude file-less buffers from a multi-buffer save, matching how a singleton untitled buffer already reports `can_save() == false`. This also covers other multi-buffer views (diagnostics, references) that could excerpt an untitled buffer.

Fixes zed-industries#60041.
@IbrahimKhan12
IbrahimKhan12 force-pushed the fix/save-multibuffer-with-untitled-buffer branch from 94b11b7 to f289f3d Compare July 21, 2026 19:02
@IbrahimKhan12
IbrahimKhan12 marked this pull request as ready for review July 21, 2026 19:02
@ChristopherBiscardi ChristopherBiscardi added the area:editor Feedback for code editing, formatting, editor iterations, etc label Jul 22, 2026
@nathansobo nathansobo self-assigned this Jul 24, 2026
@nathansobo
nathansobo added this pull request to the merge queue Jul 24, 2026
@nathansobo

Copy link
Copy Markdown
Contributor

Makes sense to me. Thank you!!

Merged via the queue into zed-industries:main with commit 051e5c6 Jul 24, 2026
46 checks passed
@zed-zippy zed-zippy Bot added the PR state:needs review Used to label PRs that are in need of a post-merge approval label Jul 24, 2026
mdz-axo added a commit to mdz-axo/zed-kask that referenced this pull request Jul 25, 2026
Upstream changes (zed-industries/zed main, 27 commits):
- agent: Add agent.compaction_model setting for context compaction (zed-industries#60012)
- agent: Show effort selector for anthropic compatible providers (zed-industries#61579)
- acp: Update agent-client-protocol SDK to 2.0.0 (zed-industries#61570)
- client: Extract proxy handshakes into new proxy_handshake crate (zed-industries#61427)
- collab: Fix multiworkspace location out of sync bugs (zed-industries#61598)
- editor: Fix sticky header drag cancels autoscroll (zed-industries#53592)
- editor: Fix crash when copying and pasting using multiple cursors (zed-industries#61545)
- editor: Skip untitled buffers when saving a multi-buffer (zed-industries#61380)
- gpui: Fix images not being drawn with rounded corners with ObjectFit::Cover (zed-industries#61383)
- gpui: Fix deadlock in performance profiler and reenable it (zed-industries#61584)
- git_ui: Prevent Git panel bindings in repository selector (zed-industries#61282)
- language_model: Add explicit OpenAI conversation compaction and fix Anthropic compaction (zed-industries#61370)
- markdown: Fix squashed Mermaid diagrams in markdown preview (zed-industries#61260)
- Opus 5 BYOK Support (zed-industries#61596)
- repl: Show add-cell controls in empty notebooks (zed-industries#61329)
- search: Escape seeded buffer search query in regex mode (zed-industries#57748)
- settings: Fix VS Code import appending duplicate file associations (zed-industries#61355)
- settings: Split VSCode and Zed keymap files (zed-industries#61532)
- Treat blank spawn_agent session IDs as absent (zed-industries#60893)
- worktree: Reload git state when a watcher rescan covers a repository (zed-industries#61541)
- Plus 7 more minor fixes.

Merge fixes:
- crates/agent/src/thread.rs: replay_tool_call used 'message_ix' (undefined)
  after auto-merge; renamed to 'owning_message_ix' (the parameter name).
- Cargo.toml: Removed stale workspace members hkask-wallet and hkask-git-cas
  (both directories deleted in prior commits but workspace entries remained).
- kask/crates/hkask-regulation/src/wallet_manager.rs: Stubbed consume() and
  settle_rjoules() on WalletBudgetPort — these were API-key encumbrance
  operations from the deleted hkask-wallet crate; regulation tracks per-agent
  gas balances, not per-key encumbrances.
- kask/crates/hkask-regulation/src/wallet_gas_calibrator.rs: Fixed test to
  use crate::agent_wallet_store::WalletStore instead of hkask_storage::WalletStore.
- kask/crates/hkask-regulation/Cargo.toml: Added tokio macros feature to
  dev-dependencies for #[tokio::test].
- kask/crates/kask_bridge/Cargo.toml: Added futures dependency (needed by
  context_injector.rs for futures::executor::block_on).
- kask/crates/kask_bridge/src/context_injector.rs: Fixed futures_util::executor
  to futures::executor (futures-util doesn't include executor module).

Release Notes:

- N/A
0arm pushed a commit to 0arm/zed that referenced this pull request Jul 26, 2026
…ies#61380)

Closes zed-industries#60041.

## Summary

When Project Search results contain both a saved file and an untitled
buffer, running `workspace: reload` did nothing (quitting hit the same
path). The log showed:

```
ERROR [.../workspace.rs] buffer doesn't have a file
```

## Root cause

The Project Search results view is an `Editor` over a multi-buffer, and
its `Item::save` delegates to `Editor::save`. For a multi-buffer,
`Editor::save` collects every dirty buffer and calls
`Project::save_buffers`. An untitled excerpt has no file, so
`BufferStore::save_buffer` returns `Err("buffer doesn't have a file")`.
That error propagates through `Pane::save_item` → `save_all_internal` →
`prepare_to_close`, which then reports the workspace as not ready to
close, so `reload`/quit silently aborts.

A singleton untitled buffer avoids this because `Editor::can_save`
returns `false` for it (the workspace routes it to `save_as`); for a
multi-buffer, `can_save` is always `true`.

## Fix

Exclude file-less (untitled) buffers when collecting the buffers to save
for a multi-buffer. Untitled buffers can only be written via `save_as`,
so a bulk multi-buffer save now persists the file-backed excerpts and
leaves untitled ones untouched. This also addresses the same latent
issue in other multi-buffer views (diagnostics, find-all-references)
that can excerpt an untitled buffer.

## Testing

- Added `test_save_multi_buffer_with_untitled_buffer_skips_untitled` in
`crates/editor/src/items.rs`: it builds a multi-buffer over a
file-backed buffer and an untitled buffer (both dirty), then asserts
`save` succeeds, the file-backed buffer is persisted, and the untitled
buffer stays dirty. Fails before this change (`buffer doesn't have a
file`), passes after.
- `cargo test -p editor --lib save` (13 tests) and `cargo test -p search
--lib project_search` (22 tests) pass.
- `./script/clippy -p editor` is clean.

Manual repro (before): new untitled buffer with text → Project Search
for a term matching both it and a saved file → `workspace: reload` →
no-op with `buffer doesn't have a file` in the log. After: reload
proceeds.

Release Notes:

- Fixed `workspace: reload` and quitting silently doing nothing when
Project Search results included an unsaved untitled buffer.
@JosephTLyons

Copy link
Copy Markdown
Collaborator

@zed-industries/approved

@zed-zippy zed-zippy Bot removed the PR state:needs review Used to label PRs that are in need of a post-merge approval label Jul 27, 2026
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…ies#61380)

Closes zed-industries#60041.

## Summary

When Project Search results contain both a saved file and an untitled
buffer, running `workspace: reload` did nothing (quitting hit the same
path). The log showed:

```
ERROR [.../workspace.rs] buffer doesn't have a file
```

## Root cause

The Project Search results view is an `Editor` over a multi-buffer, and
its `Item::save` delegates to `Editor::save`. For a multi-buffer,
`Editor::save` collects every dirty buffer and calls
`Project::save_buffers`. An untitled excerpt has no file, so
`BufferStore::save_buffer` returns `Err("buffer doesn't have a file")`.
That error propagates through `Pane::save_item` → `save_all_internal` →
`prepare_to_close`, which then reports the workspace as not ready to
close, so `reload`/quit silently aborts.

A singleton untitled buffer avoids this because `Editor::can_save`
returns `false` for it (the workspace routes it to `save_as`); for a
multi-buffer, `can_save` is always `true`.

## Fix

Exclude file-less (untitled) buffers when collecting the buffers to save
for a multi-buffer. Untitled buffers can only be written via `save_as`,
so a bulk multi-buffer save now persists the file-backed excerpts and
leaves untitled ones untouched. This also addresses the same latent
issue in other multi-buffer views (diagnostics, find-all-references)
that can excerpt an untitled buffer.

## Testing

- Added `test_save_multi_buffer_with_untitled_buffer_skips_untitled` in
`crates/editor/src/items.rs`: it builds a multi-buffer over a
file-backed buffer and an untitled buffer (both dirty), then asserts
`save` succeeds, the file-backed buffer is persisted, and the untitled
buffer stays dirty. Fails before this change (`buffer doesn't have a
file`), passes after.
- `cargo test -p editor --lib save` (13 tests) and `cargo test -p search
--lib project_search` (22 tests) pass.
- `./script/clippy -p editor` is clean.

Manual repro (before): new untitled buffer with text → Project Search
for a term matching both it and a saved file → `workspace: reload` →
no-op with `buffer doesn't have a file` in the log. After: reload
proceeds.

Release Notes:

- Fixed `workspace: reload` and quitting silently doing nothing when
Project Search results included an unsaved untitled buffer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:editor Feedback for code editing, formatting, editor iterations, etc cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

workspace: reload errors when Project Search results contain both saved file and untitled buffer

4 participants