From e8105c9a99512f736066123178b4638e1c5e3fef Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sat, 29 Jan 2022 18:23:14 +0100 Subject: [PATCH] Show a message when no matches were found --- crates/find/src/find.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/find/src/find.rs b/crates/find/src/find.rs index f1725d4b9629bcd002340ee4f1e7035eff3fd066..6b8a061892f34c4572cf38a52eadfeb3b6a57b46 100644 --- a/crates/find/src/find.rs +++ b/crates/find/src/find.rs @@ -107,14 +107,16 @@ impl View for FindBar { let (_, highlighted_ranges) = editor.read(cx).highlighted_ranges_for_type::()?; let match_ix = cmp::min(self.active_match_index? + 1, highlighted_ranges.len()); + let message = if highlighted_ranges.is_empty() { + "No matches".to_string() + } else { + format!("{} of {}", match_ix, highlighted_ranges.len()) + }; Some( - Label::new( - format!("{} of {}", match_ix, highlighted_ranges.len()), - theme.match_index.text.clone(), - ) - .contained() - .with_style(theme.match_index.container) - .boxed(), + Label::new(message, theme.match_index.text.clone()) + .contained() + .with_style(theme.match_index.container) + .boxed(), ) })) .contained()