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

avoid reloading invalid views #4889

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,20 +1049,28 @@ fn reload_all(
let docs_view_ids: Vec<(DocumentId, Vec<ViewId>)> = cx
.editor
.documents_mut()
.map(|doc| {
let mut view_ids: Vec<_> = doc.selections().keys().cloned().collect();

if view_ids.is_empty() {
doc.ensure_view_init(view_id);
view_ids.push(view_id);
};

(doc.id(), view_ids)
})
.map(|doc| (doc.id(), doc.selections().keys().cloned().collect()))
.collect();

for (doc_id, view_ids) in docs_view_ids {
// Not using filter map here means we need to clone the id again since
// contains cant be called with a reference.
#[allow(clippy::unnecessary_filter_map)]
let mut view_ids: Vec<ViewId> = view_ids
.into_iter()
// TODO: This check can be removed once
// https://github.com/helix-editor/helix/pull/4888 is merged.
.filter_map(|id| match cx.editor.tree.contains(id) {
true => Some(id),
false => None,
})
Comment on lines +1063 to +1066
Copy link
Member

Choose a reason for hiding this comment

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

I think clippy is saying here that this could be filter(|id| cx.editor.tree.contains(*id)) rather than a filter_map

Copy link
Contributor Author

@mangas mangas Nov 26, 2022

Choose a reason for hiding this comment

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

I think we should avoid being defensive here: by being defensive we might allow broken assumptions to cause hard-to-debug quirks

No worries, I wasnt sure how large a fix the close stuff would be so decided to check this route as well. I'll close the PR

.collect();

let doc = doc_mut!(cx.editor, &doc_id);
if view_ids.is_empty() {
doc.ensure_view_init(view_id);
view_ids.push(view_id);
};

// Every doc is guaranteed to have at least 1 view at this point.
let view = view_mut!(cx.editor, view_ids[0]);
Expand Down