diff --git a/crates/find/src/find.rs b/crates/find/src/find.rs index 929e9ce67b..19b105ccf8 100644 --- a/crates/find/src/find.rs +++ b/crates/find/src/find.rs @@ -110,22 +110,23 @@ impl FindBar { ) { if let Some(editor) = &self.active_editor { let search = self.query_editor.read(cx).text(cx); - if search.is_empty() { - return; - } - let search = AhoCorasick::new_auto_configured(&[search]); + let theme = &self.settings.borrow().theme.find; editor.update(cx, |editor, cx| { + if search.is_empty() { + editor.clear_highlighted_ranges::(cx); + return; + } + + let search = AhoCorasick::new_auto_configured(&[search]); let buffer = editor.buffer().read(cx).snapshot(cx); - let mut ranges = search + let ranges = search .stream_find_iter(buffer.bytes_in_range(0..buffer.len())) .map(|mat| { let mat = mat.unwrap(); - mat.start()..mat.end() + buffer.anchor_after(mat.start())..buffer.anchor_before(mat.end()) }) - .peekable(); - if ranges.peek().is_some() { - editor.select_ranges(ranges, None, cx); - } + .collect(); + editor.highlight_ranges::(ranges, theme.match_background, cx); }); } } diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index c3d37b950c..9452204617 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -24,6 +24,7 @@ pub struct Theme { pub project_panel: ProjectPanel, pub selector: Selector, pub editor: EditorStyle, + pub find: Find, pub project_diagnostics: ProjectDiagnostics, } @@ -87,6 +88,11 @@ pub struct Tab { pub icon_conflict: Color, } +#[derive(Clone, Deserialize, Default)] +pub struct Find { + pub match_background: Color, +} + #[derive(Deserialize, Default)] pub struct Sidebar { #[serde(flatten)] diff --git a/crates/zed/assets/themes/_base.toml b/crates/zed/assets/themes/_base.toml index b818b514a7..e92715793c 100644 --- a/crates/zed/assets/themes/_base.toml +++ b/crates/zed/assets/themes/_base.toml @@ -185,7 +185,7 @@ corner_radius = 6 [project_panel] extends = "$panel" -padding.top = 6 # ($workspace.tab.height - $project_panel.entry.height) / 2 +padding.top = 6 # ($workspace.tab.height - $project_panel.entry.height) / 2 [project_panel.entry] text = "$text.1" @@ -318,3 +318,6 @@ status_bar_item = { extends = "$text.2", margin.right = 10 } tab_icon_width = 13 tab_icon_spacing = 4 tab_summary_spacing = 10 + +[find] +match_background = "$state.highlighted_line"