Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic on close last buffer (#2367) #2658

Merged

Conversation

gavynriebau
Copy link
Contributor

In certain circumstances it was possible to cause a panic when closing
buffers due to some mishandling of view document history.

A change has been made to delete removed documents from the history of
accessed documents for each view. The ensures we don't attempt to jump
to a deleted document by mistake.

In certain circumstances it was possible to cause a panic when closing
buffers due to some mishandling of view document history.

A change has been made to delete removed documents from the history of
accessed documents for each view. The ensures we don't attempt to jump
to a deleted document by mistake.
@@ -826,6 +826,9 @@ impl Editor {
Some(Action::Close(view.id))
}
} else {
// documents also need be removed from the view "document access history"
// so we don't accidentally try to jump back to them after they have been deleted
view.docs_access_history.retain(|doc| doc != &doc_id);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah wait, that's not actually possible since it's a method on view.jumps. Perhaps we should add a method to View that cleans up both jumps and access history. Any place calling jumps.remove should then call this new method instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll have a go at doing it

Copy link
Contributor Author

@gavynriebau gavynriebau Jun 3, 2022

Choose a reason for hiding this comment

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

@archseer I've moved the cleanup into a view.remove_document function in commit edd5a38, take a look when you have a moment.

We could also take this approach further and add an Editor.remove_document function which would look like:

impl Editor {
  fn remove_document(&mut self, doc_id: &DocumentId) {
    for view in self.tree.views_mut() {
      view.remove_document(&doc_id);
    }
    self.documents.remove(&doc_id);
  }
}

@gavynriebau gavynriebau force-pushed the bugfix/panic-on-close-last-buffer branch from e728afc to edd5a38 Compare June 3, 2022 11:37
@archseer
Copy link
Member

archseer commented Jun 3, 2022

There's one more occurrence of view.jumps.remove in the file that needs to be changed to use the new function

@gavynriebau
Copy link
Contributor Author

There's one more occurrence of view.jumps.remove in the file that needs to be changed to use the new function

I've now switched the last occurrence of view.jumps.remove over

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants