{"record":{"id":"45532d06306a5f48","repo":"zed-industries/zed","slug":"ensured-that-there-s-only-one-selection","errorCode":null,"errorMessage":"ensured that there's only one selection","messagePattern":"ensured that there's only one selection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/editor/src/selection.rs","lineNumber":539,"sourceCode":"                for selection in &mut selections {\n                    let (word_range, _) = buffer.surrounding_word(selection.start, None);\n                    selection.start = word_range.start;\n                    selection.end = word_range.end;\n                    selection.goal = SelectionGoal::None;\n                    selection.reversed = false;\n                    self.select_match_ranges(\n                        selection.start..selection.end,\n                        selection.reversed,\n                        action.replace_newest,\n                        Some(Autoscroll::newest()),\n                        window,\n                        cx,\n                    );\n                }\n                if selections.len() == 1 {\n                    let selection = selections\n                        .last()\n                        .expect(\"ensured that there's only one selection\");\n                    let query = buffer\n                        .text_for_range(selection.start..selection.end)\n                        .collect::<String>();\n                    let is_empty = query.is_empty();\n                    let select_state = SelectNextState {\n                        query: self.build_query(&[query.chars().rev().collect::<String>()], cx)?,\n                        wordwise: true,\n                        done: is_empty,\n                    };\n                    self.select_prev_state = Some(select_state);\n                } else {\n                    self.select_prev_state = None;\n                }\n            } else if let Some(selected_text) = selected_text {\n                self.select_prev_state = Some(SelectNextState {\n                    query: self\n                        .build_query(&[selected_text.chars().rev().collect::<String>()], cx)?,\n                    wordwise: false,","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/editor/src/selection.rs#L521-L557","documentation":"A precondition guard in select_previous: the implementation computes the previous match relative to a single selection's word range and later expects the selection set to contain exactly one selection. It fires when select_previous is invoked on an editor with zero or multiple selections — the surrounding word/match logic only defines a result for the single-selection case, so the invariant 'ensured that there's only one selection' was violated.","triggerScenarios":"Thrown at crates/editor/src/selection.rs:539 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Branch on the selection count: no-op for zero, operate on the newest/last selection for multiple instead of panicking","Call the single-selection API only after checking editor.selection_count() or selecting the newest selection explicitly","Add a debug_assert! to catch multi-selection callers during development while degrading gracefully in release"],"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"}