Skip to content

Fix discard not reloading buffer from disk#48936

Merged
SomeoneToIgnore merged 5 commits intozed-industries:mainfrom
TomPlanche:TomPlanche/fix/48308-discard-retains-unsaved-edits
Feb 13, 2026
Merged

Fix discard not reloading buffer from disk#48936
SomeoneToIgnore merged 5 commits intozed-industries:mainfrom
TomPlanche:TomPlanche/fix/48308-discard-retains-unsaved-edits

Conversation

@TomPlanche
Copy link
Contributor

Closes #48308.

Before:
zed-#48308-before

After:
zed-#48308-after

Release Notes:

  • Fixed file changes not being discarded when closing a tab with "Don't Save" or "Discard all".

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 11, 2026
@zed-industries-bot
Copy link
Contributor

zed-industries-bot commented Feb 12, 2026

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against ecd65a2


let path_style = project.read_with(cx, |project, cx| project.path_style(cx));
if save_intent == SaveIntent::Skip {
let can_save = cx.update(|_window, cx| item.can_save(cx))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic seems to be wrong?

  1. can_save returns true for a multi buffer:
    fn can_save(&self, cx: &App) -> bool {
    let buffer = &self.buffer().read(cx);
    if let Some(buffer) = buffer.as_singleton() {
    buffer.read(cx).project_path(cx).is_some()
    } else {
    true
    }
    }
  2. MutliBuffer's reload will reload all its contents:
    fn reload(
    &mut self,
    project: Entity<Project>,
    window: &mut Window,
    cx: &mut Context<Self>,
    ) -> Task<Result<()>> {
    let buffer = self.buffer().clone();
    let buffers = self.buffer.read(cx).all_buffers();
    let reload_buffers =
    project.update(cx, |project, cx| project.reload_buffers(buffers, true, cx));
    cx.spawn_in(window, async move |this, cx| {
    let transaction = reload_buffers.log_err().await;
    this.update(cx, |editor, cx| {
    editor.request_autoscroll(Autoscroll::fit(), cx)
    })?;
    buffer.update(cx, |buffer, cx| {
    if let Some(transaction) = transaction
    && !buffer.is_singleton()
    {
    buffer.push_transaction(&transaction.0, cx);
    }
    });
    Ok(())
    })
    }

We do not want to reload from FS files that were not involved into the discard dialogue, do we?
Sounds like we need a multi buffer test for this and a bit more convoluted logic for a fix?

@SomeoneToIgnore SomeoneToIgnore self-assigned this Feb 12, 2026
@TomPlanche TomPlanche force-pushed the TomPlanche/fix/48308-discard-retains-unsaved-edits branch from 3d1705c to 7cb87bd Compare February 12, 2026 23:11
Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

I would expect multi buffer to discard the related changes too, but sure we can start off this — ready to merge it after CI is green.

@SomeoneToIgnore SomeoneToIgnore enabled auto-merge (squash) February 13, 2026 00:32
@TomPlanche
Copy link
Contributor Author

@SomeoneToIgnore I'll try to work on the multibuffer case, but from what I can tell, it needs some heavier changes

@SomeoneToIgnore SomeoneToIgnore merged commit 4fefc6f into zed-industries:main Feb 13, 2026
27 checks passed
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.

Zed does not discard files properly

3 participants