{"record":{"id":"2874087368ca6b31","repo":"zed-industries/zed","slug":"old-selections-isn-t-empty","errorCode":null,"errorMessage":"old_selections isn't empty","messagePattern":"old_selections isn't empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/editor/src/selection.rs","lineNumber":750,"sourceCode":"                Selection {\n                    id: selection.id,\n                    start: new_range.start,\n                    end: new_range.end,\n                    goal: SelectionGoal::None,\n                    reversed: selection.reversed,\n                }\n            })\n            .collect::<Vec<_>>();\n\n        if !selected_larger_node {\n            return; // don't put this call in the history\n        }\n\n        // scroll based on transformation done to the last selection created by the user\n        let (last_old, last_new) = old_selections\n            .last()\n            .zip(new_selections.last().cloned())\n            .expect(\"old_selections isn't empty\");\n\n        let is_selection_reversed = if new_selections.len() == 1 {\n            let should_be_reversed = last_old.start != last_new.start;\n            new_selections.last_mut().expect(\"checked above\").reversed = should_be_reversed;\n            should_be_reversed\n        } else {\n            last_new.reversed\n        };\n\n        self.select_syntax_node_history.disable_clearing = true;\n        self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {\n            s.select(new_selections.clone());\n        });\n        self.select_syntax_node_history.disable_clearing = false;\n\n        let start_row = last_new.start.to_display_point(&display_map).row().0;\n        let end_row = last_new.end.to_display_point(&display_map).row().0;\n        let selection_height = end_row - start_row + 1;","sourceCodeStart":732,"sourceCodeEnd":768,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/editor/src/selection.rs#L732-L768","documentation":"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.","triggerScenarios":"Thrown at crates/editor/src/selection.rs:750 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}