zed-industries/zed · error
old_selections isn't empty
Error message
old_selections isn't empty
What it means
An internal invariant guard in select_larger_syntax_node: after expanding selections to larger syntax nodes, the code zips the last old selection with the last new one to compute autoscroll. The expect fires if old_selections is empty at that point — the function was entered without any prior selections, meaning select_larger_syntax_node ran on an editor with no selection, which the surrounding logic assumes cannot happen.
Source
Thrown at crates/editor/src/selection.rs:750
Selection {
id: selection.id,
start: new_range.start,
end: new_range.end,
goal: SelectionGoal::None,
reversed: selection.reversed,
}
})
.collect::<Vec<_>>();
if !selected_larger_node {
return; // don't put this call in the history
}
// scroll based on transformation done to the last selection created by the user
let (last_old, last_new) = old_selections
.last()
.zip(new_selections.last().cloned())
.expect("old_selections isn't empty");
let is_selection_reversed = if new_selections.len() == 1 {
let should_be_reversed = last_old.start != last_new.start;
new_selections.last_mut().expect("checked above").reversed = should_be_reversed;
should_be_reversed
} else {
last_new.reversed
};
self.select_syntax_node_history.disable_clearing = true;
self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select(new_selections.clone());
});
self.select_syntax_node_history.disable_clearing = false;
let start_row = last_new.start.to_display_point(&display_map).row().0;
let end_row = last_new.end.to_display_point(&display_map).row().0;
let selection_height = end_row - start_row + 1;View on GitHub (pinned to 9d272b0363)
Solutions
- Return early if old_selections.is_empty() before the history/autoscroll step instead of unconditionally zipping
- Skip the autoscroll computation when there is no old selection to compare against
- Guard the action itself so it is a no-op on editors with no selections
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/editor/src/selection.rs:750 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20).
Data as JSON: /api/errors/2874087368ca6b31.
Report an issue: GitHub.