From d5d45d5e89cc6076113d37a4f905a660fc64dbc4 Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Thu, 26 Feb 2026 14:42:16 +0000 Subject: [PATCH] git: Fix a panic when searching the split diff (#50211) (cherry-pick to stable) (#50215) Cherry-pick of #50211 to stable ---- This could happen when you initiated a search on the left side, then toggled into the unified view, then tried to select the next match. Closes ZED-55G Release Notes: - Fixed a panic when toggling the split diff view while searching. Co-authored-by: Cole Miller --- crates/editor/src/split.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/editor/src/split.rs b/crates/editor/src/split.rs index bf7b9999fa9cc34cd5c28f3aed86735facf7a492..da1450acf11f0720b9784e233a7c62d0d58e7556 100644 --- a/crates/editor/src/split.rs +++ b/crates/editor/src/split.rs @@ -1108,13 +1108,11 @@ impl SplittableEditor { SearchToken::new(self.focused_side() as u64) } - fn editor_for_token(&self, token: SearchToken) -> &Entity { + fn editor_for_token(&self, token: SearchToken) -> Option<&Entity> { if token.value() == SplitSide::Left as u64 { - if let Some(lhs) = &self.lhs { - return &lhs.editor; - } + return self.lhs.as_ref().map(|lhs| &lhs.editor); } - &self.rhs_editor + Some(&self.rhs_editor) } } @@ -1753,7 +1751,10 @@ impl SearchableItem for SplittableEditor { window: &mut Window, cx: &mut Context, ) { - self.editor_for_token(token).update(cx, |editor, cx| { + let Some(target) = self.editor_for_token(token) else { + return; + }; + target.update(cx, |editor, cx| { editor.update_matches(matches, active_match_index, token, window, cx); }); } @@ -1799,7 +1800,10 @@ impl SearchableItem for SplittableEditor { window: &mut Window, cx: &mut Context, ) { - self.editor_for_token(token).update(cx, |editor, cx| { + let Some(target) = self.editor_for_token(token) else { + return; + }; + target.update(cx, |editor, cx| { editor.activate_match(index, matches, token, window, cx); }); } @@ -1811,7 +1815,10 @@ impl SearchableItem for SplittableEditor { window: &mut Window, cx: &mut Context, ) { - self.editor_for_token(token).update(cx, |editor, cx| { + let Some(target) = self.editor_for_token(token) else { + return; + }; + target.update(cx, |editor, cx| { editor.select_matches(matches, token, window, cx); }); } @@ -1824,7 +1831,10 @@ impl SearchableItem for SplittableEditor { window: &mut Window, cx: &mut Context, ) { - self.editor_for_token(token).update(cx, |editor, cx| { + let Some(target) = self.editor_for_token(token) else { + return; + }; + target.update(cx, |editor, cx| { editor.replace(identifier, query, token, window, cx); }); } @@ -1868,7 +1878,7 @@ impl SearchableItem for SplittableEditor { window: &mut Window, cx: &mut Context, ) -> Option { - self.editor_for_token(token).update(cx, |editor, cx| { + self.editor_for_token(token)?.update(cx, |editor, cx| { editor.active_match_index(direction, matches, token, window, cx) }) }